The order is important. The redirections are processed left-to-right, and "2>&1" means "send stderr to the place stdout is
now going". Subsequent redirections of stdout will not affect stderr.
Code:
ls /etc /root 2>&1 >redirectfile1
- First, redirect stderr to the place stdout is now going, which is probably the terminal. Since stderr was probably already going to the terminal, this is pretty much a no-op.
- Then, redirect stdout to file "redirectfile1". This has no effect on stderr.
I have to use words like "probably" and "pretty much" because this command might be in a script invoked with stderr and/or stdout already redirected.
Code:
ls /etc /root >redirectfile1 2>&1
- First, redirect stdout to file "redirectfile1".
- Then, redirect stderr to the place stdout is now going, i.e., the file.
Note that I did not have to use the word "probably" in the second example. Nothing there is dependent on how stderr or stdout might have been previously redirected.