the #! notation

Neil Rickert rickert at mp.cs.niu.edu
Tue Jan 22 04:48:03 AEST 1991


In article <1991Jan16.162705.580 at cid.aes.doe.CA> afsipmh at cidsv01.cid.aes.doe.CA () writes:
>
> Could someone clear up something for me?
> - If i put #! /bin/csh on the first line of a script
>   the c shell will run it. If I put #! /bin/sh the
>   Bourne shell will etc. 
> This is all well and good BUT does it assume that I am
> starting out in the c shell i.e. is the #! being interpreted
> by the c shell. What if my default were Bourne or ksh?

 If your system supports '#!', these symbols are interpreted by the kernel,
not by the shell.  A process 'exec's a new command.  The kernel checks the
'magic number' at the beginning of the file to ensure that this is an
executable binary for this processor.  If it discovers that the 'magic
number' is '#!' it reads the name of the interpreter program and loads that
instead of the original file, but with the original file name as an
argument.

 In other words '#!', if supported, will work equally from the Bourne shell,
or any other shell, or even from a C program you write yourself.

-- 
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
  Neil W. Rickert, Computer Science               <rickert at cs.niu.edu>
  Northern Illinois Univ.
  DeKalb, IL 60115                                   +1-815-753-6940



More information about the Comp.unix.shell mailing list