She Bang #! /bin/bash


The line: #! /bin/bash
#! /bin/bash
is called a shebang (or hashbang). It tells the system which interpreter should be used to execute the script.
🔍 If you include #!/bin/bash
at the top of script.sh
:
You're explicitly saying: "Use the Bash shell to run this script."
You can execute it directly like this:
./script.sh
(as long as you’ve done
chmod +x
script.sh
to make it executable)The system will invoke
/bin/bash
to interpret the script.
❌ If you omit #!/bin/bash
:
The script might still work, but:
It will be run using the default shell defined in your environment (often
/bin/sh
)./bin/sh
is not alwaysbash
. On some systems, it's a different shell likedash
, which is faster but less feature-rich.Any Bash-specific syntax (like
[[ ]]
, arrays, etc.) may break or behave differently.
✅ Best Practice:
Always use the shebang line to avoid ambiguity and ensure your script behaves consistently across systems.
Quick Example:
#!/bin/bash
echo "This is Bash-specific"
If this script uses Bash features and you run it without a shebang (or with sh
script.sh
), it might throw errors or misbehave.
Subscribe to my newsletter
Read articles from Neelesh Joshi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Neelesh Joshi
Neelesh Joshi
Hi, am a passionate programmer and front-end web developer I am interested in problem solving