Closing only stderr in a sh(1) command.

GarBear Irick irick at ecn.purdue.edu
Wed May 2 10:04:57 AEST 1990


In article <1605 at dinl.mmc.UUCP> noren at dinl.UUCP (Charles Noren) writes:
>What I want to do is:
>
>   ls *.o | some-util
>
>so that if there is no *.o files, it will not be reported.
>In other words, can I close only stderr (or redirect it to
>/dev/null) while keeping stdin and stdout unaffected?

Call me silly, but this should work...

( ls *.o > /tmp/lsfile$$ ) >& /dev/null;cat /tmp/lsfile$$ | some-util

I can't think of a one-statement equivalent that will do it off of the top of
my head.  If anyone comes up with a better solution, PLEASE post it... Just
don't exceed the 4000 degrees F limit on my anti-flame unit.

Gary A. Irick, irick at en.ecn.purdue.edu
Purdue University Engineering Computer Network



More information about the Comp.unix.questions mailing list