$linuxjunkies
>

shebang

also: hashbang, #!

A special line at the start of a script file that tells the operating system which interpreter to use to execute the script. It begins with #! followed by the path to an interpreter.

The shebang (also written as hashbang) is the first line of a script file, starting with #! followed by the absolute path to an interpreter program. When you execute the script directly (e.g., ./myscript.sh), the kernel reads this line and uses the specified interpreter to run the script, rather than trying to execute it as a binary.

For example, #!/bin/bash tells the system to use the Bash shell, while #!/usr/bin/python3 uses Python 3. You can also pass arguments to the interpreter: #!/usr/bin/env python3 is commonly used to find Python 3 in the user's PATH instead of assuming a fixed location.

The shebang only works on Unix-like systems (Linux, macOS, BSD) and must be the very first bytes of the file. Without it, you would need to explicitly call the interpreter: bash myscript.sh instead of ./myscript.sh.

Related terms