Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!sdd.hp.com!decwrl!bacchus.pa.dec.com!decvax.dec.com!ima!minya!jc From: jc@minya.UUCP (John Chambers) Newsgroups: comp.unix.shell Subject: Re: Yet Another bourne shell query Message-ID: <438@minya.UUCP> Date: 2 Sep 90 19:57:41 GMT References: <437@minya.UUCP> <3330@awdprime.UUCP> Lines: 36 In article <3330@awdprime.UUCP>, tif@doorstop.austin.ibm.com (Paul Chamberlain/32767) writes: > In article <437@minya.UUCP> jc@minya.UUCP (John Chambers) writes: > >I basically want to write something like: > > if [ ];then exec > This seems to work: > > if read x > then : okay > else > exec < /dev/null > fi > > I hope you're not going to all this trouble to use /dev/null though. No, of course not. The problem is that, if init invokes a script, and the script invokes programs that assume the standard three files are open, the result is often that some program bombs out, the shell doesn't like it and so it exits, and the script dies in its tracks. If I just wanted to use /dev/null, I'd direct the I/O there. What I want is to find out which (if any) of the standard files aren't open, and open them attached to something innocuous; for file 0, the obvious choice is /dev/null. If any of the three standard files are open, I'f like to leave them where they are, so they can be passed on to subprocesses as usual. Another problem with the above is that it gobbles down one line of standard input, so the first command that does input will miss its first line. It'd be a bit weird to tell users that input files must have a dummy first line that will be discarded, just because the script does something like this. -- Zippy-Says: Imagine ... a world without clothing folds, chiaroscuro, or marital difficulties ... Home: 1-617-484-6393 Work: 1-508-952-3274 Uucp: ...!{harvard.edu,ima.com,eddie.mit.edu,ora.com}!minya!jc (John Chambers) Uucp-map: minya adelie(DEAD)