Article View: comp.unix.shell
Article #1445Re: How to pipe stderr to a command in Bourne or Korn shell
From: Maarten Litmaath
Date: Tue, 09 Oct 1990 17:59
Date: Tue, 09 Oct 1990 17:59
28 lines
1415 bytes
1415 bytes
In article <668@atcmpe.atcmp.nl>,
henk@atcmp.nl (Henk M. Keller) writes:
)In article <1990Oct8.165133.17187@cti-software.nl>,
) pim@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)
Technical Details
Message-ID:
<7878@star.cs.vu.nl>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!uunet!mcsun!hp4nl!star.cs.vu.nl!maartReferences:
<1990Oct8.165133.17187@cti-software.nl> <668@atcmpe.atcmp.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!uunet!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.shell Subject: Re: How to pipe stderr to a command in Bourne or Korn shell Message-ID: <7878@star.cs.vu.nl> Date: 9 Oct 90 17:59:28 GMT References: <1990Oct8.165133.17187@cti-software.nl> <668@atcmpe.atcmp.nl> Sender: news@cs.vu.nl Reply-To: maart@cs.vu.nl (Maarten Litmaath) Organization: VU Dept. of Computer Science, Amsterdam, The Netherlands Lines: 28