Closing only stderr in a sh(1) command.

Bob McGowen Wyse Technology Training bob at wyse.wyse.com
Fri May 4 02:38:56 AEST 1990


In article <1990May2.000457.9488 at ecn.purdue.edu> irick at ecn.purdue.edu (GarBear Irick) writes:
>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?
yes
>
>Call me silly, but this should work...
---deleted solution---
>Gary A. Irick, irick at en.ecn.purdue.edu
>Purdue University Engineering Computer Network

With the Bourne shell, if there is no match for the wild card the argument
is passed to the command as is and the ls generates an error message on
standard error.  The following should do what you want:

   ls *.o 2>/dev/null | some-util

On my system (XENIX 2.3.2), the 2>/dev/null must follow immediately after
the ls.  If it follows "some-util", the ls error is still printed to
the screen.

Note that csh deals with wildcards somewhat differently than sh when
there is no match for the pattern.  Errors are generated by csh itself
rather than the utility and I am not sure how you would deal with
it.
Bob McGowan  (standard disclaimer, these are my own ...)
Customer Education, Wyse Technology, San Jose, CA
..!uunet!wyse!bob
bob at wyse.com



More information about the Comp.unix.questions mailing list