REDIRECTION
Before a command is executed, its input and output may be
redirected. The following may appear anywhere in a simple command or
may precede or follow a complex command. Substitution occurs before
word is used except as noted below. If the result of
substitution on word produces more than one filename,
redirection occurs for each separate filename in turn.
... 1>fname 2>&1
first associates file descriptor 1 with file fname. It then associates file descriptor 2 with the file associated with file descriptor 1 (that is, fname). If the order of redirections were reversed, file descriptor 2 would be associated with the terminal (assuming file descriptor 1 had been) and then file descriptor 1 would be associated with file fname.
If the user tries to open a file descriptor for writing more than once, the shell opens the file descriptor as a pipe to a process that copies its input to all the specified outputs, similar to tee(1). Thus:
date >foo >bar
writes the date to two files, named "foo" and "bar". Note that a pipe is an implicit indirection; thus
date >foo | cat
writes the date to the file "foo", and also pipes it to cat.
If the user tries to open a file descriptor for reading more than once, the shell opens the file descriptor as a pipe to a process that copies all the specified inputs to its output in the order specified, similar to cat(1). Thus
sort <foo <fubar
or even
sort <f{oo,ubar}
is equivalent to "cat foo bar | sort". Similarly, you can do
echo exit 0 >> *.sh
Note that a pipe is in implicit indirection; thus
cat bar | sort <foo
is equivalent to "cat bar foo | sort" (note the order of the inputs).
If a simple command consists of one or more redirection operators and zero or more parameter assignments, but no command name, the command cat is assumed. Thus
< file
prints the contents of file.
If a command is followed by & and job control is not active, then the default standard input for the command is the empty file /dev/null. Otherwise, the environment for the execution of a command contains the file descriptors of the invoking shell as modified by input/output specifications.