|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to "tee" stderr
In other words, print on both the screen and to a file (minus stdout)? Thanks again in advance
|
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
If your shell is Bash (or similar), this set of redirections will do the job: Code:
$ command 3>&1 1>&2 2>&3 | tee file What does it mean? The redirection operator n>&m makes file descriptor n to be a copy of file descriptor m. So, whe are: - Opening a new file descriptor, 3, that is a copy of file descriptor 1, the standard output; - Making file descriptor 1 a copy of file descriptor 2, the standard error output; - Making file descriptor 2 to be a copy of file descriptor 3 (the "backup" of the standard output) in a short: we swapped the standard output and the standard error output. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Quote:
Code:
cat valid_filename invalid_filename 2>&1 1>/dev/null | tee output_filename Last edited by shamrock; 04-20-2011 at 09:32 PM.. Reason: update |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk command to replace ";" with "|" and ""|" at diferent places in line of file | shis100 | Shell Programming and Scripting | 7 | 03-16-2011 08:59 AM |
| tar "--totals" writes to stderr not stdout? | jelloir | Shell Programming and Scripting | 2 | 09-13-2010 01:28 PM |
| Why stderr file descriptor redirection makes ksh's "select" construct hang. | kchinnam | Shell Programming and Scripting | 11 | 05-08-2010 04:59 AM |
| Adding custom mesg. when redirecting "exec 2>stderr.err" ? | snurani | Shell Programming and Scripting | 0 | 07-10-2008 12:19 PM |
| passing "stderr " to a subroutine.. | sekar sundaram | Shell Programming and Scripting | 1 | 11-29-2005 07:14 PM |
|
|