*** Welcome to piglix ***

Shebang (Unix)


In computing, a shebang is the character sequence consisting of the characters number sign and exclamation mark (#!) at the beginning of a script. It is also called sha-bang,hashbang,pound-bang, or hash-pling.

Under Unix-like operating systems, when a script with a shebang is run as a program, the program loader parses the rest of the script's initial line as an interpreter directive; the specified interpreter program is run instead, passing to it as an argument the path that was initially used when attempting to run the script. For example, if a script is named with the path path/to/script, and it starts with the following line:

then the program loader is instructed to run the program /bin/sh instead, passing path/to/script as the first argument.

The shebang line is usually ignored by the interpreter because the "#" character is a comment marker in many scripting languages; some language interpreters that do not use the hash mark to begin comments (such as Scheme) still may ignore the shebang line in recognition of its purpose. Other solutions rely on a preprocessor that evaluates and removes the shebang line and sends the remainder of the script to a compiler or interpreter.

The form of a shebang interpreter directive is as follows:

in which interpreter is an absolute path to an executable program. The optional argument should either not be included or it should be a string representing a single argument. White space after #! is optional.

Some typical shebang lines:

Shebang lines may include specific options that are passed to the interpreter. However, implementations vary in the parsing behavior of options; for portability, only one option should be specified without any embedded whitespace. Further portability guidelines are found below.

Interpreter directives allow scripts and data files to be used as commands, hiding the details of their implementation from users and other programs, by removing the need to prefix scripts with their interpreter on the command line.


...
Wikipedia

...