Search code examples
posixstandardslanguage-lawyershebanglsb

Is the Shebang (#!) standardized?


Is the Shebang #!, e.g.

#!/bin/sh

in front of script executables officially standardized in the Linux Standard Base or in any of The Open Group standards or elsewhere? If yes, please provide references and details.

NOTE: I'm most interested in its meaning for shell scripts as well as for any executable file. In other words, do any of the standards require shebang-like interpretation of #! at the beginning of executable files? However, any other references to it in the standards are also welcome.


Solution

  • POSIX leaves the effect of #! unspecified. From 2.1 Shell Introduction

    The shell reads its input from a file (see sh), from the -c option or from the system() and popen() functions defined in the System Interfaces volume of POSIX.1-2008. If the first line of a file of shell commands starts with the characters "#!", the results are unspecified.