Shell programming style -- a pl

Guy Harris guy at rlgvax.UUCP
Sun Mar 11 16:24:41 AEST 1984


When Doug said that "#!/bin/sh" at the beginning of a shell file would force
the shell file to be executed on 4.2BSD, S3, and S5, I think he meant "S3 and
S5 which haven't hacked the Bourne shell Berkeley-style to run scripts which
begin with "#" with the C shell".  That hack (having the Bourne shell run
scripts that begin with "#" with the C shell, and having the C shell run
scripts that begin with ":" with the Bourne shell) was done *before* "#"
was allowed as a comment character in Bourne shell scripts.  Now that it
*is* allowed, that hack is based on an invalid assumption and should not
be implemented.  As such, any *sane* S3/S5 implementation of the Bourne
shell won't feed scripts to the C shell if the script begins with "#".
If you want to have a way to have scripts "select" the shell that they're
to be executed by, the best solution is to bite the bullet and implement
"#!".  It's only 236 bytes of code on the VAX (I've pulled the code
out and compiled it!), permits you to implement set-UID shell scripts, and
has been blessed - hell, it was *invented* - by Dennis Ritchie himself.

I know at least one commercial V7 micro-based system with the C shell
implemented the heuristic based on the rule "Bourne shell scripts do not
begin with '#', and C shell scripts do not begin with ':'", which was
true in V7.  It's *not* true in S3 or S5, so if anybody puts the C shell
into their USG system they will *break things* if they put that rule into
the Bourne shell.  There are Bourne shell scripts *distributed with S3 and
S5* which begin with "#", so don't even *think* about putting that heuristic
in!  If you need to put in some way to identify scripts as Bourne or C
shell scripts, *please* send your $600 or whatever it is to the University
of California, get a 4.xBSD tape, and implement "#!".

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Comp.unix mailing list