Cshell within make

Guy Harris guy at sun.uucp
Fri Jan 17 05:56:38 AEST 1986


> Strange, I couldn't find this (#! /bin/csh) in the documentation I have,
> although I probably didn't look far enough.

It's done by the kernel, so check EXECVE(2) in the System Interface Manual
(which is what Sun calls sections 2, 3, 4, and 5).

> Indeed, the documentation seemed to imply that *any* comment starting at
> the first character of a file would cause the script file to be run in csh,
> surely a strange practice...  And #/bin/csh worked everywhere that I tried
> it, until I tried make.  (Leaving it out would result in the same file
> being run by sh.)  Why is make different?

Yes, it is a strange practice.  A little bit of the history behind it:

The original V7 shell (and the V6 shell, as well - I think the C shell first
appeared under V6) handled "comments" with a command called ":".  This
command didn't do anything, so it "threw out" what followed it.  (However,
what followed it had to be syntactically legal, and if it happened to
include I/O redirection, the I/O redirection was done anyway.) The C shell
supported real comments; a "#" anywhere on a line caused the scanner to
ignore the rest of the line.  The creators of the C shell wanted to have a
way for the C shell to recognize regular shell scripts, and *vice versa*.
This was so that you could write scripts for either shell and have it be
executed by the correct shell, no matter what shell you were running.  The
"#!" feature in the kernel didn't exist at that point, so they couldn't use
it.  They decided that any script which began with a regular shell comment -
i.e., the first character of the script was ':' - was a regular shell
script, and any script that began with a C shell comment - i.e., the first
character of the script was '#' - was a C shell script.

Since then, the '#!' stuff was put into 4BSD (and maybe 2.9BSD), so the old
rules aren't necessary.  Those rules aren't too cool any more, either, since
the Bourne shell in 4.xBSD and in Systems III and V support the same comment
style as the C shell, so "if it begins with '#' it's a C shell script"
simply isn't true anymore (especially if it begins with "#! /bin/sh"!).

The reason "make" is different is that "make" doesn't always run its command
lines from the shell - if the command line doesn't have anything on it that
requires the use of the full shell (i.e., no shell metacharacters), it runs
the command itself to speed things up.  "make", unlike the Bourne and C
shells, doesn't have the ':' vs. '#' rule built into it, so it runs
*everything* with the same shell, which is the Bourne shell (unless your
"make" uses the SHELL make/environment variable).

> A few observed that "make" should look at the SHELL variable.  It doesn't
> on our system (BSD 4.2), and a note today in news from Matthew P Wiener
> (of the Math Dept at UCB) says that the line in "make" that checks SHELL
> is usually commented out in the BSD version.  Anybody know why?

For a good guess at why - and for an explanation of why "make" should NOT
look at the SHELL variable - see my response to Rob Bernardo's posting on
this subject.

	Guy Harris



More information about the Comp.unix mailing list