How to pipe stderr to a command in Bourne or Korn shell

Maarten Litmaath maart at cs.vu.nl
Wed Oct 10 03:59:28 AEST 1990


In article <668 at atcmpe.atcmp.nl>,
	henk at atcmp.nl (Henk M. Keller) writes:
)In article <1990Oct8.165133.17187 at cti-software.nl>,
)	pim at cti-software.nl (Pim Zandbergen) writes:
)> 
)> How can one redirect stderr to a command while leaving stdout unaffected ?
)
)The real solution in sh and ksh is to exchange stdout and stderr:
)
)	command_1 3>&1 1>&2 2>&3 3>&- | command_2

But that still does _not_ answer Pim's question!
He said: `... while leaving stdout _unaffected_' (emphasis added).
In Henk's example stdout is dup(2)ed to stderr.

So:
	exec 3>&1
	command_1 2>&1 1>&3 3>&- | command_2 3>&-
	exec 3>&-

Or:
	3>&1 (command_1 2>&1 1>&3 3>&- | command_2 3>&-)

	# yes Virginia, that's correct

Don't forget to close the extra descriptor, or you'll get screwed one day.
--
            "the C shell is flakier than a snowstorm."  (Guy Harris)



More information about the Comp.unix.shell mailing list