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.
Linux – the difference between redirection 2>&1 1>file.txt and >a.txt 2>&1
linuxredirection
Related Question
- Linux – the difference between fsck and e2fsck
- Linux – the difference between mlocate and slocate in Linux
- Linux – the difference between &> and >& in bash
- Linux – the difference between the system group and netgroup
- Linux – Difference between locate and which in Linux
- Why it is 2>&1 and not 2>>&1 to append to a log file
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.