Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!nrl-cmf!ukma!gatech!mcnc!rti!sunpix!matthew From: matthew@sunpix.UUCP ( Sun NCAA) Newsgroups: comp.unix.questions Subject: Re: #! /bin/sh line in a shell script Message-ID: <382@greens.UUCP> Date: 1 Feb 89 16:48:59 GMT References: <8575@orstcs.CS.ORST.EDU> Organization: Sun Microsystems, Research Triangle Park, NC Lines: 28 In article <8575@orstcs.CS.ORST.EDU>, ghe@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 |