Path: 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 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)