Redirection quirks: 2>&1 >file -- vs. -- >file 2>&1

Ken Turkowski ken at turtlevax.UUCP
Sat Jan 4 04:22:28 AEST 1986


In article <649 at watmath.UUCP> idallen at watmath.UUCP writes:
>    $ command 2>&1 >file
>    $ command >file 2>&1
>These are not equivalent using our 4.2bsd Bourne shell.  (The 2>&1 in the
>first line redirects unit 2 to the tty, not to the file.)
>Is this a feature or a bug?  Comments not worthy of world-wide
>net readership should be mailed to me, not posted, please.

Yes, this is how it works.  Redirections are parsed and executed in
order, so that in the first case, fd2 is dup'ed from fd1, and then fd1
is redirected, and in the second case fd1 is redirected, followed by
fd2 being dup'ed from the new fd1.
-- 
Ken Turkowski @ CIMLINC, Menlo Park, CA
UUCP: {amd,decwrl,hplabs,seismo,spar}!turtlevax!ken
ARPA: turtlevax!ken at DECWRL.DEC.COM



More information about the Comp.unix.wizards mailing list