#!magic, details about the shebang/hash-bang mechanism on various Unix flavours
3 days ago
- #Unix
- #ShellScripting
- #History
- The #! (shebang) mechanism was introduced between Version 7 and Version 8 Unix, first implemented in 4.0BSD (~10/'80) but not activated by default.
- Early implementations had limitations: the line length was limited to 16 or 32 bytes, and arguments were not delivered.
- The mechanism was later implemented by default in 4.2BSD (~09/'83), delivering all #! arguments as a single one.
- 2.8BSD (~07/'81) also added #! but not active by default, with code slightly different from 4BSD.
- The #! mechanism was removed in 4.3BSD Net/2 due to licensing issues and had to be reimplemented in descendants like NetBSD, 386BSD, and BSDI.
- Linux introduced #! with kernel release 0.09 or 0.10, with original maximum length of 1022 bytes, later reduced to 127.
- Different Unix systems handle #! lines differently: some deliver all arguments as one string, some split them, and some deliver only the first argument.
- env(1) is often used with #! to start an interpreter from PATH, but its location varies across systems, affecting portability.
- Setuid support for scripts was disabled in 4.3BSD-Tahoe and not present in 4.4BSD; later systems like NetBSD and Linux implemented it with certain conditions.
- The term 'shebang' likely comes from shortening 'sharp-bang' or 'shell bang', influenced by American slang 'the whole shebang'.