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

carl carl at bdaemon.UUCP
Mon Jan 6 14:50:24 AEST 1986


> In article <649 at watmath.UUCP> idallen at watmath.UUCP writes:
> >Consider:
> >
> >    $ 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} 

Carl Brandauer
{allegra|amd|attunix|cbosgd|ucbvax|ut-sally}!nbires!bdaemon!carl



More information about the Comp.unix.wizards mailing list