Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!bellcore!decvax!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.unix,net.unix-wizards Subject: Re: "#! /bin/sh" vs ":" Message-ID: <2144@sun.uucp> Date: Tue, 30-Apr-85 00:50:47 EDT Article-I.D.: sun.2144 Posted: Tue Apr 30 00:50:47 1985 Date-Received: Thu, 2-May-85 01:22:01 EDT References: <183@ski.UUCP> Organization: Sun Microsystems, Inc. Lines: 46 Xref: watmath net.unix:4397 net.unix-wizards:13007 > There are at least 2 ways of indicating to csh that a Shell script > should be interpreted by sh: begin the file with: > > #! /bin/sh > > or with any character other than "#", such as: > > : > > These two ways are not equivalent, but I can't characterize the > difference. The first, on 4.xBSD systems, possibly 2.[89]BSD systems, other systems which have been modified to support the kernel detecting executable interpreter scripts (I think Masscomp's system does so), and systems where the C shell has been modified to recognize "#!" comments, causes the kernel (in most cases) to execute the program whose pathname is given after the "#!", with the zeroth argument (i.e., command name) and first argument which are both the pathname of the script. The second, on 4.xBSD systems, possibly 2.[89]BSD systems, and on most other systems running the C shell, causes the C shell to run "/bin/sh" on the script. WARNING: beginning with ':' is NOT a necessary condition for being a Bourne shell script. The 4.xBSD Bourne shell, and the System III and V Bourne shells (as well as, I presume, the Korn shell) permit "#" comments which are real comments, not no-op commands. > The first sometimes causes commands in the script to fail with the > error message "restricted" This is because some versions of the Bourne shell look at their zeroeth argument (which, in most cases, is their own path name) to see if it contains the letter 'r' anywhere, or in the better shells only in the last component of the path name (so being in "/usr/bin" won't confuse them). If it does, it considers itself a "restricted" shell and forbids all sorts of things, like commands with '/' in their name, changing PATH, redirecting output, etc.. > and produces a funny command line in ps -f: > > file file This is because, as mentioned, both the zeroth and first arguments to "/bin/sh" are the name of the file. Guy Harris