Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: notesfiles Path: utzoo!linus!vaxine!wjh12!genrad!decvax!harpo!seismo!hao!hplabs!hp-pcd!hp-dcd!rml From: rml@hp-dcd.UUCP Newsgroups: net.unix Subject: Re: Re: csh misconceptions Message-ID: <34500003@hp-dcd.UUCP> Date: Mon, 19-Mar-84 22:02:00 EST Article-I.D.: hp-dcd.34500003 Posted: Mon Mar 19 22:02:00 1984 Date-Received: Tue, 6-Mar-84 01:04:17 EST References: <16953@sri-arpa.UUCP> Organization: Hewlett-Packard Fort Collins Systems Division - Fort Collins, CO Lines: 61 Nf-ID: #R:sri-arpa:-1695300:hp-dcd:34500003:000:2487 Nf-From: hp-dcd!rml Mar 1 19:02:00 1984 Suppose I run csh as my login shell on a non-Berkeley system, and I execute a script beginning with #!/bin/sh The following steps (as you have outlined) will occur: >> (1) The kernel is asked to execv() it. One of two things can happen: >> >> (a) If the script starts with #!progname etc. then the kernel >> arranges for the script to be attached to the standard input of >> the specified program, typically /bin/sh or /bin/csh, which >> takes it from there. 1b applies only to Berkeley systems; it does not apply here, so we continue to >> >> (b) Otherwise, the execv() returns to the Cshell with an >> ENOEXEC error indication. >> >> (2) If there is an alias defined for "shell", then the Cshell will >> prepend that to the command and try another execv(). The person who has aliased shell has taken control over which shell will be executed away from the script. This requires a specific action on the part of that person. Assume this is not the case. >> (3) Otherwise, if the first character of the script is a # character, >> the shell specified in the "shell" environment variable is prepended, >> or if there is none specified "/bin/csh" is used. This would usually >> be /bin/csh for most Cshell users. The resulting command is execv()ed. This is the case which takes place. Since this is a login shell, Cshell has set its "shell" environment varibale to /bin/csh. The script, which begins #!/bin/sh, is thus fed to the Cshell. >> >From the above, it is clear that the ONLY way to ensure that a Bourne >> shell script is interpreted by /bin/sh as intended is to supply the >> first line >> >> #!/bin/sh From this example, I state that the ONLY way to ensure that a Bourne shell script is interpreted by /bin/sh as intended is to supply a first character which is not #. The #!program is counterproductive not only for backward compatibility with versions of sh which don't recognize # as a comment character, but for compatibility with non-Berkeley UN*X systems. I generally write Bourne shell scripts with a first line like: : this is a Bourne shell script not a Cshell script If someone does invoke this script from the Cshell with shell aliased to /bin/csh, the Cshell will complain about the first line. It recognizes : as a goto label, but does not allow it to have arguments. Because : is not a true comment character, beware of lines like : don't invoke with csh Bob Lenk {hplabs, inhp4}!hpfcla!rml