Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!jarthur!bridge2!mips!wyse!bob From: bob@wyse.wyse.com (Bob McGowen Wyse Technology Training) Newsgroups: comp.unix.questions Subject: Re: Closing only stderr in a sh(1) command. Message-ID: <2711@wyse.wyse.com> Date: 3 May 90 16:38:56 GMT References: <1605@dinl.mmc.UUCP> <1990May2.000457.9488@ecn.purdue.edu> Sender: news@wyse.wyse.com Reply-To: bob@wyse.UUCP (Bob McGowen Wyse Technology Training) Organization: Wyse Technology Lines: 34 In article <1990May2.000457.9488@ecn.purdue.edu> irick@ecn.purdue.edu (GarBear Irick) writes: >In article <1605@dinl.mmc.UUCP> noren@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@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@wyse.com