One of the common questions about the Bourne and Korn shells is why
only the second command will redirect both
to a file:
cat food 2>&1 >file
cat: can't open food
cat food >file 2>&1
Although lots of
manual pages don't mention this, the shell reads
arguments from left to right.
On the first command line, the shell sees
That means "make the standard error (file descriptor 2) go to the same
place as the standard output (fd1) is going."
There's no effect because both fd2 and fd1 are already going to the terminal.
redirects fd1 (
But fd2 (
) is still going to the terminal.
On the second command line, the shell sees
sends fd2 (
) to the same place fd1 is
going - that's to the file.
And that's what you want.
has much more about the