magic numbers

Robert Elz kre at mulga.SUN
Thu Mar 8 17:24:08 AEST 1984


The point of doing '#!' stuff inside the kernel is that it allows
setuid interpreted programs (including 'sh' scripts as a special case).

That can't be accomplished in any library routine, no matter
how hard you try.

With that, shell scripts become as versatile as
compiled (a.out format) executables, you can ALWAYS use
whichever is most appropriate, without being stopped by
implementation restrictions - which is just as it should be.

Another effect, is that the name of the script (interpreted
program) goes in /usr/adm/acct instead of the ubiquitous 'sh'.

I might add that the original idea & code to do this were
by Dennis Ritchie (if my sources are correct, & they are
fairly good sources I think), and I added it to 4.1bsd.

Robert Elz
decvax!mulga!kre

ps: the code is reasonably portable, the "magic number" is the
string "#!", it works, as is, whichever way your bytes are arranged.
And yes, its fractionally slower than treating the magic number
as some horrible octal constant!



More information about the Comp.unix.wizards mailing list