Strange behaviour of /bin/sh -c (4.2 BSD)

Brett Galloway brett at wjvax.UUCP
Fri Feb 28 04:06:43 AEST 1986


I ran across what appears to be strange behaviour in the Bourne shell (sh),
when one brings up a program using sh -c.  Note that sh -c foo brings up
program foo running under /bin/sh.  If one does this from the csh, as

	sh -c foo &

as I understand it, that should bring up /bin/sh running foo, in the background,
but /bin/sh's stdin and stdout should still be connected to the control
terminal.  Apparently, even when -c is used, sh thinks it is in interactive
mode.

That behaviour is questionable enough.  What is even more peculiar is that
if one brings up sh -c foo NOT connected to a terminal, it still does
this!  For example, do

	sh -c foo </dev/null >&/dev/null &

from the csh.  This puts /bin/sh -c foo with stdin, stdout, and stderr connected
to /dev/null, and runs it in the background (which is a nop in this case,
since /bin/sh is not connected to the terminal anyhow).  It is clear that
/bin/sh should not assume that it is interactive, since /dev/null is not
a terminal, yet it appears to do so, insofar as it ignores SIGINT.  Apparently,
the -c flag of sh effectively forces the -i (interactive) flag.

What I would like to know is whether this is a bug of /bin/sh, a (mis)feature,
or whether I am missing something.  Please respond via mail, and I will
summarize.

Thanks (in advance).

-------------
Brett Galloway
{pesnta,twg,ios,qubix,turtlevax,tymix,vecpyr,certes,isi}!wjvax!brett



More information about the Comp.unix.wizards mailing list