What is the difference between redirection ./prog 2>&1 1>file.txt
and ./prog >a.txt 2>&1
? It looks that ./prog 2>&1 1>file.txt
doesn't save stderr to file but this ./prog >a.txt 2>&1
does.
Difference Between Redirection 2>&1 1>file.txt and >a.txt 2>&1 in Linux
linuxredirection
Best Answer
Redirection operators are examined left-to-right, thus
first redirects standard-output to
bar
and then redirect standard-error to the location where standard-output is redirected at this point (thusbar
, too).first redirects standard-error to what standard-output points to (most probably the terminal) and then redirects standard-output to
bar
.Short: first one redirects both
stdout
andstderr
tobar
, second one redirects onlystdout
tobar
andstderr
to terminal.