#! in shell scripts

ed at unisoft.UUCP ed at unisoft.UUCP
Sun Mar 18 12:01:10 AEST 1984


It is my understanding that the #! magic number was suggested by
Dennis Ritchie and implemented by Dennis and/or Bill Joy.  In
any case, the idea seems to have come from Bell.

Its original motivation was not particularly for shell scripts,
however, but to deal with the output of "pi", which is a translator
from Pascal to an interpreted intermediate code.  To execute the
intermediate, "px" is used.  It seemed nice to be able to utter
just the name of the pi output file to get it executed, rather
than "px filename".  (There was actually a kludge put in to the
pi output files to make them executable, but it was pretty expensive
to start up as it involved an extra fork, exec, and pipe.)
Thus was born the "specified interpreter" magic number #!.
These characters were chosen for compatibility with existing
shell scripts.

Having the kernel recognize this extra magic number, as has been
pointed out by several others, is not particularly expensive,
since the kernel already reads the exec header from the file
to determine if it's executable at all.

-- 
Ed Gould
ucbvax!mtxinu!ed



More information about the Comp.unix mailing list