#! /bin/sh line in a shell script

Sun NCAA matthew at sunpix.UUCP
Thu Feb 2 02:48:59 AEST 1989


In article <8575 at orstcs.CS.ORST.EDU>, ghe at nucthy.physics.orst.edu (Guangliang He) writes:
> I have seen number of times that a shell script file begining with a line
> #! /bin/sh. What does that mean? 
> 
> I know that any shell script file begining with a # sign is treated as
> a c-shell script and the following content of that line is treated as
> comment.

    This little tidbit from a man page should help you figure it out.

     When a pathname is found that  has  proper  execute  permis-
     sions,  the  shell  forks a new process and passes it, along
     with its arguments to the kernel (using the execve(2) system
     call).   The kernel then attempts to overlay the new process
     with the desired program.  If  the  file  is  an  executable
     binary (in a.out(5), the kernel succeeds, and begins execut-
     ing the new process.  If the file is a text  file,  and  the
     first  line begins with #!, the next word is taken to be the
     pathname of a shell (or command) to interpret  that  script.
     Subsequent  words on the first line are taken as options for
     that shell.  The kernel  invokes  (overlays)  the  indicated
     shell, using the name of the script as an argument.


-- 
Matthew Lee Stier     (919) 469-8300|
Sun Microsystems ---  RTP, NC  27560|          "Wisconsin   Escapee"
uucp: {sun, rti}!sunpix!matthew     |



More information about the Comp.unix.questions mailing list