#!magic, details about the shebang/hash-bang mechanism on various Unix flavours

https://news.ycombinator.com/rss Hits: 11
Summary

Bourne | Ash | #! | find | ARG_MAX | Shells | whatshell | portability | permissions | UUOC | ancient | - | ../Various | HOME "$@" | echo/printf | set -e | test | tty defs | tty chars | $() vs ) | IFS | using siginfo | nanosleep | line charset | locale The #! magic, details about the shebang/hash-bang mechanism on various Unix flavours 2001-08-13 .. 2021-10-20 (see recent changes) Here you'll find More reading The Origin See an old mail from Dennis Ritchie introducing the new feature, quoted in 4.0 BSD /usr/src/sys/newsys/sys1.c. The path component newsys was an option. It is also mentioned in /usr/src/sys/sys/TODO (that is, in the regular path), 6. Exec fixes Implement dmr's #! feature; pass string arguments through faster. So this #! mechanism origins from Bell Labs, between Version 7 and Version 8, and was then available on 4.0BSD (~10/'80), although not activated per default. Two important differences to current implementations are: The length of the line was limited to 16 (Research Unix) or 32 (BSD) bytes. "Arguments" were not delivered. It was then implemented by default on 4.2BSD (~09/'83), /usr/src/sys/sys/kern_exec.c by Robert Elz. This implementation delivered all #! arguments as a single one. Less than a year after 4.0BSD, but more than two years before 4.2 BSD, #! was also added to 2.8BSD (~07/'81), but not active by default. 2.x BSD is a different development line, independent from 4 BSD. It's a 7th edition (V7) kernel with fixes activated by macros. The macro for the #! code is not present in a makefile, so you had to activate it yourself. The code wording is slightly different from 4 BSD. On 2.8 BSD, #! seems to come from the U.S. Geological Survey in Menlo Park, not from Berkeley. (Thanks to Gunnar Ritter for pointing out the origins in 4.0 and 4.2BSD in de.comp.os.unix.shell, to Jeremy C. Reed for mentioning Robert Elz, and to Richard Kettlewell for spotting 2.8BSD on TUHS mailing list.) In 4.3BSD Net/2 the code was removed due to the license war and...

First seen: 2025-11-20 07:02

Last seen: 2025-11-20 17:05