The Shebang Line
The shebang is like the name label on a lunchbox that says who should open it. It tells the computer which helper program should read and run the file.
In this page:
Syntax
#!/path/to/interpreter
# script commands follow
The Shebang Line
The first line of a script, #!/bin/bash, is the shebang — it tells the operating system which interpreter should run the file when executed directly.
Without it, ./script.sh might use the wrong shell and behave unexpectedly. The shebang must be the very first line, with no blank line above it.
Note:
#!/usr/bin/env bash is a more portable shebang that finds bash wherever it is on the PATH.Example: The Shebang Line
#!/bin/bash
# This shebang tells the OS to run this file with bash
echo "Running under: $0"
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
Common Mistakes
- Putting a space or a blank line before
#!, so it is not read as a shebang and the system uses a default shell. - Writing a wrong interpreter path such as
#!/bin/bsh, which givesbad interpreter: No such file or directory. - Saving the script with Windows line endings (CRLF), so the interpreter is read as
bash\rand fails.
🔒
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: