Shell programming style -- a pl
Guy Harris
guy at rlgvax.UUCP
Tue Mar 6 16:07:33 AEST 1984
> The only safe form I know of (for forcing a shell script to be executed
> by "sh" and not "csh" - gh) across ALL systems is to write a script that
> begins with a space...
I believe beginning the script with a colon will also work.
For those of you who have tuned in late, all versions of the Bourne shell,
even the V7 one, treat the colon as a command which throws away its arguments
and returns an "exit status" of 0 (it sort of acts like a comment, but it will
parse the text after the colon as arguments to a command, so beware of shell
meta-characters), while the C shell treats it as a signal to run the script
with "/bin/sh". We've used it on several occasions and it works fine. The
4.xBSD Bourne shell, and some other Bourne shells on systems with "csh", treat
a script whose *first character* is "#" as something to be run by "csh"
(elsewhere, "#" is just a comment in some Bourne shells), so beginning a
script with "#" may fail for one of the three following reasons:
1) Your Bourne shell may think it flags the script as a C shell script;
2) Your Bourne shell may not know the C shell from Adam, but doesn't understand
that "#" introduces a comment;
3) You used the "#! /bin/sh" construct to force it to be executed by "/bin/sh",
but your system doesn't have the trick (originally concocted by an employee
of Bell Labs, by the way) of the "magic number" "#!" introducing an executable
file header which indicates the pathname of an interpreter to be used to
interpret the contents of the file.
Guy Harris
{seismo,ihnp4,allegra}!rlgvax!guy
More information about the Comp.unix
mailing list