Yet Another bourne shell query
John Chambers
jc at minya.UUCP
Mon Sep 3 05:57:41 AEST 1990
In article <3330 at awdprime.UUCP>, tif at doorstop.austin.ibm.com (Paul Chamberlain/32767) writes:
> In article <437 at minya.UUCP> jc at minya.UUCP (John Chambers) writes:
> >I basically want to write something like:
> > if [ <file 0 is open> ];then exec</dev/null;fi
>
> 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)
More information about the Comp.unix.shell
mailing list