Your First Script
Your first script is like writing your first three-step recipe: a label at the top, a few instructions, and notes to remind yourself why. Save it, run it, and watch the computer follow along.
In this page:
Syntax
#!/bin/bash
# describe what the script does
variable_name="value"
echo "message with $variable_name"
Your First Script
A complete first script combines the shebang, a few commands, and comments explaining intent. Saving it with a .sh extension is a convention, not a requirement — Bash doesn't care about file extensions.
What matters is the shebang line and execute permission.
Note:
Keep your first scripts small and test them often rather than writing many commands before running anything.
Example: Your First Script
#!/bin/bash
# My first Bash script
echo "Starting script..."
name="World"
echo "Hello, $name!"
echo "Script finished."
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
- Forgetting the
#!/bin/bashline at the top of the script. - Forgetting to make the script executable, then getting
Permission denied. - Using a relative path inside the script and running it from another directory, so files are not found.
🔒
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: