What is a shebang (#!) line?
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated 2026-10-20
- tool
- Bash
- versions
- any
- os
- linux, macos
A shebang is the first line of a script, starting with #!, that names the program used to run it. When you execute the file directly (./script.sh), the kernel reads that line and runs the named interpreter with the script path as an argument. Running it as bash script.sh ignores the line.
Example
printf '#!/usr/bin/env bash\necho "interpreter: bash $BASH_VERSINFO, script: $0"\n' > hello.sh
chmod +x hello.sh
./hello.shOutput
interpreter: bash 5, script: ./hello.sh
Common shebang lines
| Line | Runs with |
|---|---|
| #!/usr/bin/env bash | the first bash on PATH (portable) |
| #!/bin/bash | bash at a fixed path |
| #!/bin/sh | the system POSIX shell (dash on Debian and Ubuntu) |
| #!/usr/bin/env python3 | the first python3 on PATH |
| #!/usr/bin/env -S node --no-warnings | node with arguments (env -S splits them) |
Details that bite
- The line must be the very first line, starting at byte 0, with no space before
#!. - A Windows line ending makes the kernel look for an interpreter named
bash\r, soenvfails withNo such file or directoryand showsbash\rin the message. Convert the file withdos2unixor save it with LF endings. - Without the execute permission (
chmod +x) the kernel refuses to run the file and bash reports exit status 126. #!/bin/shscripts must not use bash-only syntax such as[[ ]]or arrays.
Sources
Related pages
flags · bashset -euo pipefail: what each flag does in bashset -e exits on the first failing command, -u treats unset variables as errors and -o pipefail makes a pipeline fail if any command in it fails. Examples.cheat sheets · bashBash cheat sheet: variables, tests, loops and expansionsBash cheat sheet with the syntax you use daily: variables, parameter expansion, tests, loops, functions, arrays, redirection and safe script headers on a page.codes · bashBash exit codes: 0, 1, 2, 126, 127, 128+n and 255What bash exit codes mean: 0 success, 1 general error, 2 misuse of builtins, 126 not executable, 127 not found, 128+n killed by signal n, and how to read $?.