csh misconceptions
rml at hp-dcd.UUCP
rml at hp-dcd.UUCP
Tue Mar 20 13:02:00 AEST 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
More information about the Comp.unix
mailing list