1

I am having a hard time understanding the difference between the order of 1>&2 and >. For example, I have file and file and don't have fie. Then diff fie file2 gives me error and I try redirecting the error message to stdout as follows:

$ diff fie file2 > out.log 2>&1
$ cat out.log
diff: fie: No such file or directory

However, if I reverse the order as

$ diff fie file2 2>&1 > out2.log
diff: fie: No such file or directory
$ cat out2.log
$ 

the output is different. Why is this? and if the STDERR and STDERR are merged by 2>&1, will the file descriptor 2 be empty? and can anyone point to a reference about >& and <& ? Thank you.

wkde
  • 125
  • 1
    Also https://unix.stackexchange.com/questions/23964/why-is-redirecting-stderr-to-dev-null-done-this-way , https://unix.stackexchange.com/questions/84279/is-this-a-typo-in-bash-manuals-redirection-section , https://unix.stackexchange.com/questions/16360/understand-a-sequence-of-redirections and the example into the reference manual about order of redirection: https://www.gnu.org/software/bash/manual/html_node/Redirections.html – thanasisp May 23 '22 at 20:37
  • 1
    2>&1 basically means "take whatever it is that fd 1 points to right now, and make fd 2 also point to the same place" – ilkkachu May 23 '22 at 20:50
  • Thank you so much! – wkde May 23 '22 at 21:06

0 Answers0