# sign in shell/cshell scripts...
Dave Martindale
dave at onfcanim.UUCP
Fri Apr 18 03:40:51 AEST 1986
In article <237 at Shasta.ARPA> ALEX at SU-SIERRA.ARPA writes:
>Hi,
> I'm encountering weird problems with sh (and sometimes csh)
>dying on some shell scripts depending on whether or not my first line in
>the script is a comment like:
>
> I am looking for ANY hint/story/random knowledge concerning
># in shell scripts.
In the beginning, there was only the one true shell, and it knew that
shell scripts were to be run by itself.
In recent times, many versions of UNIX support the convention that a
script beginning with #! signals that a particular (arbitrary) program
is to be used to execute the script, and invoking the correct interpreter
is handled by the kernel.
Sometime in between those two times, there existed UNIX systems that had
both a "sh" shell and a "csh" shell but no "#!" mechanism, and the shells
(or at least the csh) established a convention that a shell script
the began with a comment ('#') was a csh script, otherwise it was a sh
script.
So, your shell is probably one of these shells, and is deciding to run
either sh or csh depending on where you put your first comment.
Since the control structures for sh and csh are so different, no wonder
the chosen shell gets indigestion if fed a script written for the other
shell.
Note that even if your kernel does support #!, the old code in the sh/csh
may not have been disabled. But it doesn't matter - if you do have #!,
just begin your scripts with "#! /bin/sh" or "#! /bin/csh -f" as
appropriate.
More information about the Comp.unix.wizards
mailing list