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

Jonathan I. Kamens jik at athena.mit.edu
Tue Oct 9 06:40:53 AEST 1990


In article <6133 at ge-dab.GE.COM>, coleman at sunny.DAB.GE.COM (Richard Coleman) 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 ?
|> For csh and bash try       (command > temp1) >& temp2
|> For sh                      command 2> temp

  The original poster asked how to redirect to a *command*.  You've shown how
to redirect to a *file*.

  In csh, one possible way to do it (when working at a tty) would be:

    (program > /dev/tty) |& command

A similar approach will work in sh (and probably ksh), although there's
probably some better way to do it with various hideous file descriptor
reassignments (I don't use the bourne shell a lot, so I don't qualify to
invent hideous file descriptor reassignments :-):

    (program > /dev/tty) 2>&1 | command

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710



More information about the Comp.unix.shell mailing list