Redirection quirks: 2>&1 >file -- vs. -- >file 2>&1
Fred Fish
fnf at well.UUCP
Sun Jan 5 09:02:09 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.)
As I'm sure many others will point out, the action is entirely reasonable.
Arguments are processed as found, so in the first command, 2>&1 says
to send 2's stuff to wherever 1 is going. Since both are probably already
going to the tty, it is effectively a no-operation. The later >file then
sends 1's stuff off to "file". In the second command, by the time 2>&1 is
processed, 1 is already going to "file", so 2 goes there too.
-Fred
--
===============================================================================
Fred Fish (415) 644-1230 ext 242 ucbvax!unisoft!fnf well!fnf
===============================================================================
More information about the Comp.unix.wizards
mailing list