On Sun, Sep 11, 2016 at 1:39 PM, Doug McIlroy <doug@cs.dartmouth.edu> wrote:
> IIRC #! originated at Bell Labs but it got out to the world via BSD.
> Perhaps Dr. McIlroy could confirm / deny / expand upon the details (please?)

I recall Dennis discussing the feature at some length before installing it.
So the exact semantics, especially the injected argument, are almost]
certainly his. I don't know whether he built on a model from elsewhere.
#! appeared between v7 (1979) and v8 (1985). As v8 was never released,
it clearly made its way into the world via BSD and USG. BSD, being
more nimble, was likely first.

Also, 8th edition was essentially a re-port of 4.1c BSD, correct? If it were already in BSD, it could conceivably come back into 8th edition via that route. I found the following in /usr/src/sys/sys/TODO for 4.0BSD:

6. Exec fixes
        Implement dmr's #! feature; pass string arguments through faster.

That would strongly imply that the feature originated with Dennis and was known in Berkeley around the time for 4BSD.

4.0's 'getxfile()' in /usr/src/sys/sys/sys1.c does not recognize the '#!' sequence as a magic number, but 'exece()' in /usr/src/sys/newsys/sys1.c does. No mention of it came up in my cursory scan of 3bsd. So it was certain present by the time of 4.1c, but not before 4BSD that I found.

        - Dan C.