From 9a7583521e381251faa2b043b9069adcf6167a77 Mon Sep 17 00:00:00 2001 From: tocariimaa Date: Tue, 4 Mar 2025 13:50:03 -0300 Subject: [PATCH] articles/shebang.md: new article --- articles/shebang.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 articles/shebang.md diff --git a/articles/shebang.md b/articles/shebang.md new file mode 100644 index 0000000..6b114a0 --- /dev/null +++ b/articles/shebang.md @@ -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.