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

Tom Christiansen tchrist at convex.COM
Sat Oct 13 12:09:59 AEST 1990


In article <7980005 at hpopd.HP.COM> ian at hpopd.HP.COM (Ian Watson) writes:
>I've seen loads of shell scripts start with 
>#!/bin/sh
>as the first line.
>
>I understand that the C shell sees this and knows to execute it as a Bourne
>shell script.  

On any system I've seen, it's the kernel who recognizes this (often 
in sys/kern_exec.c) and launches the proper interpreter.  

I happen to believe that doing anything else than this is undesirable --
currently either csh or sh may end up being called (on a BSD system) if
the program doesn't have either the magic number of compiled a.out or an
interpreter line, depending on the first character (# or not) of the file.

--tom
--
 "UNIX was never designed to keep people from doing stupid things, because 
  that policy would also keep them from doing clever things." [Doug Gwyn]



More information about the Comp.unix.questions mailing list