Skip to content

/glossary/bash/shebang

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

bash
printf '#!/usr/bin/env bash\necho "interpreter: bash $BASH_VERSINFO, script: $0"\n' > hello.sh
chmod +x hello.sh
./hello.sh

Output

interpreter: bash 5, script: ./hello.sh

Common shebang lines

LineRuns with
#!/usr/bin/env bashthe first bash on PATH (portable)
#!/bin/bashbash at a fixed path
#!/bin/shthe system POSIX shell (dash on Debian and Ubuntu)
#!/usr/bin/env python3the first python3 on PATH
#!/usr/bin/env -S node --no-warningsnode 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, so env fails with No such file or directory and shows bash\r in the message. Convert the file with dos2unix or 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/sh scripts must not use bash-only syntax such as [[ ]] or arrays.

Sources