Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcrdcf!hplabs!hao!seismo!brl-tgr!gwyn From: gwyn@brl-tgr.ARPA (Doug Gwyn) Newsgroups: net.unix Subject: Re: 2 shell questions before the new year Message-ID: <6822@brl-tgr.ARPA> Date: Fri, 28-Dec-84 22:14:49 EST Article-I.D.: brl-tgr.6822 Posted: Fri Dec 28 22:14:49 1984 Date-Received: Sun, 30-Dec-84 02:00:06 EST References: <6820@brl-tgr.ARPA> Organization: Ballistic Research Lab Lines: 25 > > 2. Why begin a shell script with > > > > #!/bin/sh > > or > > #!/bin/csh > > This tells the C shell which shell is supposed to interpret the > shell script. It's necessary because the syntax of shell > commands is different in the two shells; I think /bin/sh is used > by default. However, if the script starts with a # and doesn't > have the ! construct, the C shell is used Let's get this right, please. Recent BSD kernels understand the "#!" as a "magic number" and exec() succeeds in executing such a file, feeding it to the specified interpeter (which need not be one of the "shells"). Only if an attempt to exec() fails will the shell decide that it's a shell script and interpret it directly. It is extremely unfortunate that the Cshell thinks that # is not found in Bourne shell scripts; apart from the #! line, practically all of my Bourne shell scripts start with a # comment describing the function. The full story of which shell will run your script was discussed several months ago and is too gross to repeat. Suffice it to say, indicate with #! which shell you want and persuade your Cshell to interpret #! lines if your kernel doesn't.