How does #!/bin/sh work ? Why does it sometimes not ?

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Oct 13 01:36:54 AEST 1990


In article <7980005 at hpopd.HP.COM> ian at hpopd.HP.COM (Ian Watson) writes:
>#!/bin/sh

On systems that support this, the kernel takes care of it as indicated
under EXEC(2) in the reference manual.

>I understand that the C shell sees this ...

Normal shells first try to exec() the file, and if that fails due to
unknown executable image format then MIGHT peek at the FIRST character
to determine whether or not a Bourne shell or C-shell should be used
to interpret the file.  The C-shell often is set up to decide that an
initial '#' character indicates the file is a C-shell script, but of
course that is not a reliable test.  Other shells simply always use a
Bourne shell, which is what I recommend.  It is possible that somebody
has hacked their shells to try to apply full #!-style decoding in lieu
of having support for it in exec(), but that would be pretty awful.



More information about the Comp.unix.questions mailing list