Running Scripts
Running a script is like handing a recipe to a cook: you can either say 'please follow this recipe' each time, or stick a note on it that says the cook may use it on their own.
In this page:
Syntax
bash script_name.sh
chmod +x script_name.sh
./script_name.sh
Running Scripts
A Bash script is run either by passing it to the bash interpreter directly, or by making it executable and running it as its own program.
bash script.sh always works regardless of permissions. Running it directly as ./script.sh requires execute permission on the file first.
Note:
bash script.sh works even without execute permission, since you're invoking bash explicitly.Example: Running Scripts
# Run with the interpreter directly
bash script.sh
# Or make it executable and run it directly
chmod +x script.sh
./script.sh
⚠️ Run this in your own terminal or Node.js environment.
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
- Running
hello.shwithout./, so the shell looks inPATHand reportscommand not foundfor a script in the current directory. - Running
./hello.shwithout execute permission, which givesPermission denied; usechmod +xorbash hello.sh. - Running a script with
sh script.shand expecting Bash features, sinceshmay be a simpler shell.
🔒
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: