Note that the order of redirections is significant.  For example, the command          ls > dirlist 2>&1   directs both standard output and standard error to the file dirlist,    while the command          ls 2>&1 > dirlist   directs  only  the  standard  output  to  file  dirlist,  because the    standard error was duplicated from the standard output before the standard   output was redirected to dirlist.Now, that last part is confusing to me.  In that case, any standard error would be printed to the terminal and any STDOUT would go to the dirlist file.  That is what would happen, but that is not how I understand the manual.  It seems like it should say because the standard error was duplicated from the standard output AFTER the standard output was redirected to dirlist.  If STDERR was sent to STDOUT before STDOUT was directed to a file, then wouldn't the file contain STDOUT AND STDERR?  Can someone please clear this up for me?  Is it just poor reading comprehension on my part?  The use of the word duplication seems a little strange to me in this context.  Perhaps that is throwing me.
Is this a typo in Bash manual's redirection section?
bash;shell;io redirection
Duplication is really the important part here. Let's see where the file descriptors are going to before redirection. This is normally the current terminal, e.g.:STDOUT ---> /dev/pts/1STDERR ---> /dev/pts/1Now, if we call ls -l without redirection, output and error messages go to my terminal under /dev/pts/1.If we first redirect the STDOUT to a file (ls -l > dirlist), it looks like this:STDOUT ---> /home/bon/dirlistSTDERR ---> /dev/pts/1When we then redirect STDERR to a duplicate of STDOUT's file descriptor (ls -l > dirlist 2>&1), STDERR goes to a duplicate of /home/bon/dirlist:STDOUT ---> /home/bon/dirlistSTDERR ---> /home/bon/dirlistIf we would first redirect STDERR to a duplicate of STDOUT's file descriptor (ls -l 2>&1):STDOUT ---> /dev/pts/1STDERR ---> /dev/pts/1and then STDOUT to a file (ls -l 2>&1 > dirlist), we would get this:STDOUT ---> /home/bon/dirlistSTDERR ---> /dev/pts/1Here, STDERR is still going to the terminal.You see, the order in the man page is correct. Testing RedirectionNow, you can test that yourself. Using ls -l /proc/$$/fd/, you see where STDOUT (with fd 1) and STDERR (with fd 2), are going for the current process:$ ls -l /proc/$$/fd/total 0lrwx------ 1 bon bon 64 Jul 24 18:19 0 -> /dev/pts/1lrwx------ 1 bon bon 64 Jul 24 18:19 1 -> /dev/pts/1lrwx------ 1 bon bon 64 Jul 24 07:41 2 -> /dev/pts/1lrwx------ 1 bon bon 64 Jul 24 18:19 255 -> /dev/pts/1Let's create a small shell script that shows where your file descriptors are pointed. This way, we always get the state when calling ls, including any redirection from the calling shell. $ cat > lookfd.sh#!/bin/shls -l /proc/$$/fd/^D$ chmod +x lookfd.sh(With CtrlD, you send an end-of-file and so stop the cat command reading from STDIN.)Now, call this script with varying combinations of redirection:$ ./lookfd.sh total 0lrwx------ 1 bon bon 64 Jul 24 19:08 0 -> /dev/pts/1lrwx------ 1 bon bon 64 Jul 24 19:08 1 -> /dev/pts/1lrwx------ 1 bon bon 64 Jul 24 19:08 2 -> /dev/pts/1lr-x------ 1 bon bon 64 Jul 24 19:08 255 -> /home/bon/lookfd.sh$ ./lookfd.sh > foo.out$ cat foo.out total 0lrwx------ 1 bon bon 64 Jul 24 19:10 0 -> /dev/pts/1l-wx------ 1 bon bon 64 Jul 24 19:10 1 -> /home/bon/foo.outlrwx------ 1 bon bon 64 Jul 24 19:10 2 -> /dev/pts/1lr-x------ 1 bon bon 64 Jul 24 19:10 255 -> /home/bon/lookfd.sh$ ./lookfd.sh 2>&1 > foo.out$ cat foo.out total 0lrwx------ 1 bon bon 64 Jul 24 19:10 0 -> /dev/pts/1l-wx------ 1 bon bon 64 Jul 24 19:10 1 -> /home/bon/foo.outlrwx------ 1 bon bon 64 Jul 24 19:10 2 -> /dev/pts/1lr-x------ 1 bon bon 64 Jul 24 19:10 255 -> /home/bon/lookfd.sh$ ./lookfd.sh > foo.out 2>&1$ cat foo.out total 0lrwx------ 1 bon bon 64 Jul 24 19:11 0 -> /dev/pts/1l-wx------ 1 bon bon 64 Jul 24 19:11 1 -> /home/bon/foo.outl-wx------ 1 bon bon 64 Jul 24 19:11 2 -> /home/bon/foo.outlr-x------ 1 bon bon 64 Jul 24 19:11 255 -> /home/bon/lookfd.shYou can see, that the file descriptors 1 (for STDOUT) and 2 (for STDERR) vary. For fun, you could also redirect STDIN and see the result:$ ./lookfd.sh < /dev/zerototal 0lr-x------ 1 bon bon 64 Jul 24 19:18 0 -> /dev/zerolrwx------ 1 bon bon 64 Jul 24 19:18 1 -> /dev/pts/1lrwx------ 1 bon bon 64 Jul 24 19:18 2 -> /dev/pts/1lr-x------ 1 bon bon 64 Jul 24 19:18 255 -> /home/bon/lookfd.sh(Question left to the reader: Where does file descriptor 255 point? ;-))