I was trying to redirect both
stderr to a file today, and I came across this:
<command> > file.txt 2>&1
This apparently redirects
stdout first, and then the resulting
stdout is redirected to
However, why isn't the order
<command> 2>&1 > file.txt? One would naturally read this as (assuming execution from left to right) the command being executed first, the
stderr being redirected to
stdout and then, the resulting
stdout being written to
file.txt. But the above only redirects
stderr to the screen.
How does the shell interpret both the commands?