What Is a Shebang Line?

A shebang line is the special first line of a script (like #!/bin/bash or #!/usr/bin/env python3) that tells the operating system which interpreter should ru...

Published November 22, 2026

A shebang is the first line of a script, starting with #!, that tells the operating system which interpreter should run it, such as #!/usr/bin/env python3. It lets you run the file directly as ./script.

The concept

When you execute a file, the kernel reads the shebang and launches the named interpreter with the file as its argument. The file must be executable (chmod +x).

Using /usr/bin/env finds the interpreter on the PATH, which is more portable than hard-coding a location.

What the kernel does

./hello.py
→ reads '#!/usr/bin/env python3'
→ runs: /usr/bin/env python3 ./hello.py

Practical examples

Python script

#!/usr/bin/env python3
print('hello')

Make it executable and run

chmod +x hello.py
./hello.py

Bash and Node

#!/usr/bin/env bash
set -euo pipefail

#!/usr/bin/env node

Windows

Windows ignores shebangs; use the py launcher or WSL

Common mistakes

  • Forgetting chmod +x.
  • Windows line endings (CRLF) breaking the interpreter name.
  • A blank line or space before #!.

Key takeaways

  • First line #! picks the interpreter.
  • Needs execute permission.
  • Use env for portability.

FAQ

Is it needed if I run python file.py?

No, it only matters when executing the file directly.

Why does it say bad interpreter?

Wrong path or CRLF line endings in the file.

More Linux articles