This does not make sense to me.
wibble > /dev/null 2>&1
I think it would make more sense if it was something like this:
wibble 2>&1 > /dev/null
In other words
Commands Output Sendall STDERRORS to STDOUT then SEND it all to /dev/null
What is the thinking behind the order of the command redirection xxx > /dev/null 2>1
?
Best Answer
The redirects are processed from left to right. If you do
The first redirect makes
stderr
point to the stream thatstdout
points to at that time (which is your tty essentially). It doesn't makestderr
an alias ofstdout
.Then
stdout
is redirected to the bit bucket. Thestdout
redirect doesn't affect the previousstderr
redirect.stderr
still refers to your tty.So:
will print only the error message on your terminal.
The
bash
redirection documentation page mentions this explicitly: