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
Practical examples
Python script
#!/usr/bin/env python3
print('hello')Make it executable and run
chmod +x hello.py
./hello.pyBash and Node
#!/usr/bin/env bash
set -euo pipefail
#!/usr/bin/env nodeWindows
Windows ignores shebangs; use the py launcher or WSLCommon 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.