weird sh(1) behaviour

Guy Harris guy at gorodish.Sun.COM
Wed Aug 3 07:10:10 AEST 1988


> I noticed a peculiarity in sh which causes me a lot of trouble.

No, you've noticed a peculiarity in "rm" that causes you trouble.

> If you do think so, create a file which contains the command 
> rm core
> Try both versions in a dir without a file named core.
> sh file will give you an error message "No such file...", while
> sh <file won't.
> The same holds when sh is used in a pipe.

"sh file" causes the shell to run all commands in "file" with the shell's
standard input as their standard input.  So does "sh <file".  The difference is
that the shell's standard input is probably your terminal in the first case,
and certainly not the terminal in the second case.

If you run the 4BSD "rm" from something other than a terminal, it acts as if
you gave it the "-f" flag.  This flag appears to suppress most error messages.

> I've played with the options of sh, but to no avail.
> Can somebody explain this behaviour to me, and tell me how I can 
> communicate through popen with the (a) shell, without losing my error
> messages.

See above for the explanation.  As for getting this to work via "popen", you
may be out of luck.



More information about the Comp.unix.wizards mailing list