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.
What is the shebang? The shebang is a special character sequence in a script file that specifies which program should be called to run the script. The shebang is always on the first line of the file, and is composed of the characters #! followed by the path to the interpreter program.
Among UNIX shell (user interface) users, a shebang is a term for the "#!" characters that must begin the first line of a script. In musical notation, a "#" is called a sharp and an exclamation point - "!" - is sometimes referred to as a bang. Thus, shebang becomes a shortening of sharp-bang.
Definition of shebang : everything involved in what is under consideration —usually used in the phrase the whole shebang.
Shebangs should never really be necessary on any platform. If a shell script lacks a shebang, the script will be interpreted by whatever shell binary was called to interpret it. This is usually the same shell binary as the shell from which you invoked the script.
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.
From the source:
Bash scripts often begin with #! /bin/bash (assuming that Bash has been installed in /bin), since this ensures that Bash will be used to interpret the script, even if it is executed under another shell.
You can also check this The #! magic, details about the shebang/hash-bang mechanism on various Unix flavours
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With