The shebang is the line at the very top of a script that begins with the two characters #! and names the program that should interpret the rest of the file. The Linux execve(2) manual page defines it directly: an interpreter script is a text file that has execute permission enabled and whose first line is of the form ”#!interpreter [optional-arg]”. Those first two bytes are a magic number; the kernel recognizes them and treats what follows as a path to an interpreter rather than as machine code.
The mechanism solves a basic problem. When a user runs a file by name, the kernel must decide how to execute it. A compiled binary carries a recognizable header the kernel knows how to load directly. A script is just text and cannot run on its own. The shebang lets the kernel handle both uniformly: on seeing #!, it instead launches the named interpreter and hands the script to it. As the execve(2) page describes, the interpreter is invoked as “interpreter [optional-arg] path arg…”, so the interpreter receives the optional argument from the shebang line, then the path of the script itself, then the original arguments the user supplied.
This indirection is what makes a script feel like a real command. A file beginning with #!/bin/bash is run by Bash; one beginning with #!/usr/bin/python3 is run by the Python interpreter; the user never has to type the interpreter’s name. The same plain text file becomes an executable program purely because of its first line and its execute bit.
The kernel imposes limits worth knowing. The execve(2) manual notes that the text following #! has a maximum length: before Linux 5.1 it was capped at 127 characters, and from Linux 5.1 onward the limit is 255 characters, with anything beyond simply ignored. This is why deeply nested interpreter paths can occasionally be silently truncated, and why the env trick, #!/usr/bin/env python3, is popular: it keeps the shebang path short and stable while letting PATH resolve where the real interpreter lives.
The shebang has been part of Unix since early implementations recognized the first two bytes of a file as #! and used the remainder of the line as the command interpreter. The convention spread to virtually every Unix-like system and remains the standard way to make any scripting language executable. It is a tiny piece of design, just two bytes, that quietly unifies compiled and interpreted programs under one launch mechanism.
Because the shebang is interpreted by the kernel and not by any one shell, it works the same whether a script is launched from Bash, from another script, or from a program calling execve directly. That universality is exactly why it has endured: it is the lowest common layer at which a text file declares what it is.