Redirection quirks: 2>&1 >file -- v

geoff at ISM780B.UUCP geoff at ISM780B.UUCP
Tue Jan 7 00:53:00 AEST 1986


>    $ command 2>&1 >file
>    $ command >file 2>&1
>These are not equivalent using our 4.2bsd Bourne shell.

It's a feature.  The N > &M says direct descriptor N to wherever
discriptor M is currently going. (if N is NULL, "1" is assumed.) The
command line is parsed left to right.  This feature allows you to (e.g.)
swap stdout and stderr so that stderr goes into a pipe for further
processing, (and stdout goes wherever else you want it).
Otherwise there would be no good way to get anything other than stdout
into a pipeline _by itself_.  A silly example:
$  make 2>&1 >make.out | wc -l | xargs -n1 -i echo You had {} errors.
counts only the error and warning message lines from the make output.
Not that this is the only way to do that.

	Geoffrey Kimbrough -- Director of Dangerous Activities --
	    {decvax!vortex || ihnp4!allegra!ima}!ism780!geoff
    If I can be of any help, you're in worse trouble than I thought.



More information about the Comp.unix.wizards mailing list