articles/shebang.md: new article

This commit is contained in:
tocariimaa 2025-03-04 13:50:03 -03:00
parent 6c825e65a1
commit 9a7583521e

16
articles/shebang.md Normal file
View file

@ -0,0 +1,16 @@
# 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](unix.md). The function of a shebang is to allow an arbitrary script written in
any [programming language](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](lua.md).
When a script with a shebang is executed, the [kernel](kernel.md) 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](shell_script.md) (here for a [POSIX](posix.md) 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](python.md) interpreter.