1.3 KiB
Shebang
A shebang is a special line at the top of scripts that start with the character sequence #!
followed
by a path to an interpreter, optionally followed by any arguments meant to be supplied to it. It was
first used in Unix. The function of a shebang is to allow an arbitrary script written in
any programming language with the executable bit set to be executed as a
native executable. The first character (#
) is usually a comment in most scripting languages -- and
languages that don't use it for comments commonly support the shebang as an special case, like Lua.
When a script with a shebang is executed, the kernel interprets the line and tries to execute the interpreter specified in the line; if it succeeds then the kernel forwards the script to be actually executed by that interpreter.
A common shebang is #!/bin/sh
, which is used in shell scripts (here for a POSIX sh).
Because the path has to be absolute, this create problems for interpreters that may not be in a standard path,
so for other languages, env
is actually called to resolve the actual path of the interpreter. For example,
#!/usr/bin/env python3
will attempt to search for the actual path of the Python interpreter.