[TUHS] History of #! interpretation in Unix

Sven Mascheck mascheck at in-ulm.de
Sun Jan 16 23:20:39 AEST 2011

John Cowan wrote:
> Warren Toomey scripsit:

> > the history of #! interpretation in System V. I couldn't find any #!
> > code in the kernels before SysVR4. 

> The feature was added to the 8th Research edition kernel,
> but didn't migrate to the System III/V line until SVR4.  

Thanks to you all.  Amazing, it came so "late".

> Shebangs began very early in BSD as a csh-only hack, but appeared
> as a config option in kernels as early as 2.8BSD, according to
> Wikipedia; 4.2BSD was the first release that turned them on by
> default.

In a usenet discussion with G.Ritter in '01 I noticed the first detailed
hint about the origin, and since then I've tried my best to document
the issue on http://www.in-ulm.de/~mascheck/various/shebang/#origin

(And although someone added some of the links I collected,
 I believe Wikipedia still has several things mixed up,
 while I'm quite busy to keep my own stuff consistent...)

4.0BSD had incorporated it originally among the BSDs.
2.8BSD came soon, sounds earlier, but after its original release,
2BSD was just a different development line (http://www.levenez.com/unix/unix_a4.pdf).

As you mention "shebangs began .. as csh-only hack":
I still wonder if one may call the BSD csh-hack as origin,
because #! might have been developed independently at Bell Labs.
(although, in turn, the idea might origin from Berkeley, as the
 interesting answer from DMR in the wikipedia article suggests.)
And BTW: it was not "csh-only", but sh was hacked symmetrically :)

> Perl has always (I think) had its own shebang support; you can get Perl
> to exec an arbitrary interpreter for a script provided it has a shebang.

The traditional ash, bash-1 (and -2 ff. as compile time option) also
implement that.

> Modern shells will use /bin/sh to run scripts that *don't* have shebangs,
> except for ksh which considers itself /bin/sh-compatible, and therefore
> runs such scripts itself.

I thought sh-like shells in general try to interprete scripts themselves
upon an ENOEXEC.  Do you know certain shells which actually call "/bin/sh"?


More information about the TUHS mailing list