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 >>& outfilewould 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> errfilewill 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.