3 ms·
Be careful when redirecting STDERR to STDOUT if yo uare also planning to redirect STDOUT to a file. The order in which things are done affects the outcome. Th
by kbenson 13y ago
Be careful when redirecting STDERR to STDOUT if yo uare also planning to redirect STDOUT to a file. The order in which things are done affects the outcome. These are not the same:
# Redirect STDOUT to file, and STDERR to file
command >/tmp/command.out 2>&1
# Redirect STDOUT to file, and STDERR to screen (as STDOUT)
command 2>&1 >/tmp/command.out
The important thing to remember is that 2>&1 is redirecting to what STDOUT is currently pointing to, not redirecting to STDOUT itself.
- scbrg 13y agoThank you for posting that. I always knew the two behaved differently, and how - but I never really understood why. Your final line cleared that up.
- TorKlingberg 13y agoRecent version of bash support the (much nicer) csh syntax: command >& /tmp/command.out
- kbenson 13y agoI wanted to mention that in the original post, but I can never remember the syntax and was rushed. :(