<tt>2>, >&</tt>: Standard Diagnostic Output



next up previous contents
Next: |: Pipes Up: Input/Output Redirection Previous: ;;;;;;: Standard

2>, >&: Standard Diagnostic Output

The redirection of the standard diagnostic output is not quite as simple as the other two. It is actually different in the C shell and in the Bourne shell.

In the C shell, >& is used to redirect both the output AND the diagnostic message(s) to a file. Therefore, using the previous example,

cat file >>& outfile
would cause both the output and the error messages (diagnostic output) to be appended to outfile.

The standard output and error may be put in two different files by using

(cat file > outfile) >& errfile

In the Bourne and the Korn shells, it is possible to separate the diagnostic output from the standard output:

cat file >> outfile 2> errfile
will cause the output of cat to append to outfile, and the error messages to go to errfile. Note that the redirection is 2>.

In order for the error and output to go to the same place, the following is used:

cat file >> outfile 2>&
(the & really means the first descriptor, which happens to be the new standard output). If the error messages are to be ignored:
cat file >> outfile 2> /dev/null
/dev/null is a special file which acts like an infinite sink.



Super-User
Fri Feb 17 15:55:40 EST 1995