SoftwareUnixshebangDennis Ritchiehistory
The #! at the top of every Unix script began as a 1980 kernel patch that read only 16 characters of the line
Dennis Ritchie announced it in a Bell Labs mail as a fix for ps, accounting and set-user-ID scripts, and Berkeley's own csh trick was never the same feature.

The announcement is short enough to quote nearly whole. “The system has been changed so that if a file being executed begins with the magic characters #! , the rest of the line is understood to be the name of an interpreter for the executed file,” Ritchie wrote in a mail stamped “Thu Jan 10 04:25 1980” from the Bell Labs machine named “research.”
Then comes the line that dates it. “At the moment the whole line is restricted to 16 characters but this limit will be raised.” Sixteen characters fits #! /bin/sh with a few to spare. It does not fit #!/usr/local/bin/something-with-a-real-name, which script authors have been discovering by accident ever since.
Before the patch, a text file with the executable bit set only worked because the shell noticed the kernel couldn’t run it and ran it as a script instead. Ritchie says as much: “Previously (and in fact still) the shell did much of this job; it automatically executed itself on a text file with executable mode when the text file’s name was typed as a command.”
That arrangement worked until you asked anything of the kernel. His mail lists five benefits, and they read like a bug list for the old way. Scripts “can be the subject of ‘exec.’” Run ps while one is going and “its real name appears instead of ‘sh’,” and accounting is “done on the basis of the real name.” Shell scripts “can be set-user-ID.” And it is “simpler to have alternate shells available; e.g. if you like the Berkeley csh there is no question about which shell is to interpret a file.”
The pitch was a sales brochure aimed at people who wrote shell scripts: “To take advantage of this wonderful opportunity, put #! /bin/sh at the left margin of the first line of your shell scripts.” It also settles a piece of folklore. The mail itself says “Blanks after ! are OK,” so a space after the shebang was allowed from day one, and any claim that it was ever required has to come from somewhere other than Ritchie.
Credit is messier than the mail suggests. On the Unix Heritage Society list in 2011, John Cowan wrote that “dmr came up with the idea of putting shebang processing into the kernel,” but that where it started as a shell feature “has to be the CSRG,” Berkeley’s research group. Jeremy Reed answered with precursors, and none matched. Bill Joy’s csh in 2BSD and 3BSD had an OTHERSH feature: a script starting with # went to csh, and anything else to /bin/sh. That chooses a shell. It does not name an interpreter. Reed says he still doesn’t “see the same #! feature.”
The thread also quotes dates for the Berkeley side: the feature was in BSD “by April 1981,” and in 2BSD by December 16, 1981, but only when built with a MENLO_SCRIPT option Reed couldn’t find documented anywhere. One poster concludes “the idea was not developed separately at Berkeley.” That is a mailing-list reading of old source code, not a proof.
Whether Ritchie’s limit was ever raised on his own machine, the mail doesn’t say.
My money says the next language that wants to act like a script will arrive the same way: no new execution model, just one line at the top of a file and a kernel willing to read it. The trick has outlived most of the systems it was written for because copying it costs nothing.
Sixteen characters and a promise.