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

Joseph S. D. Yao jsdy at hadron.UUCP
Tue Jan 7 00:47:41 AEST 1986


In article <350 at bdaemon.UUCP> carl at bdaemon.UUCP (carl) writes:
>> 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.)
>The real explanation for all of this is that once a Bourne shell command
>line has been read (up to \n or ; or & etc.) it is evaluated from right to
>left.  To convince yourself, try
>	foobar=${foo}${bar} foo="hello" bar=" world"
>versus
>	foo="hello" bar=" world" foobar=${foo}${bar} 

Since the '>'s are obviously interpreted left to right, this can't be
universally true.  Apparently, some things are interpreted left-right
and others right-left.  Actually, I would have expected the
assignments to be interpreted in parallel, and so in both they would
have assigned foobar = "".
-- 

	Joe Yao		hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}



More information about the Comp.unix.wizards mailing list