programming#bash#shell#linux
Bash Scripting: The Basics You'll Use Every Week
Variables, loops, conditionals and pipes in Bash — enough to automate 90% of everyday tasks.
Bash Basics
Bash is the default shell on Linux/macOS. Learn a little and you'll automate hours of clicking.
Your first script
hello.sh:
#!/usr/bin/env bash
name=${1:-World} # first argument, or "World" if missing
echo "Hello, $name!"
chmod +x hello.sh
./hello.sh Priya # Hello, Priya!
Variables
count=5 # NO spaces around =
echo "count is $count"
Conditionals
if [[ $count -gt 3 ]]; then
echo "big"
elif [[ $count -eq 3 ]]; then
echo "medium"
else
echo "small"
fi
Loops
for f in *.log; do
gzip "$f"
done
i=0
while (( i < 3 )); do
echo $i
((i++))
done
Pipes and redirects
ls -la | grep '.py$' | wc -l # count Python files
python script.py > out.log 2>&1 # capture stdout + stderr
Real-world example
Nightly backup:
#!/usr/bin/env bash
DATE=$(date +%F)
tar -czf "/backups/notes-$DATE.tgz" /var/notes
find /backups -name 'notes-*.tgz' -mtime +14 -delete
Beginner tip
Always quote variables ("$name"), always run shellcheck script.sh — it catches 95% of bash bugs.
Keep reading
You may also like
programming
Python Async: A Practical Guide
asyncio, event loops and when NOT to use async.
Read
programming
React 19 useOptimistic Explained
The new hook that makes optimistic UI trivial — with a working example.
Read
programming
Python for Absolute Beginners
The absolute essentials of Python — variables, if, loops and functions — in the clearest possible words, with runnable examples.
Read
Discussion (0)
No comments yet. Be the first to weigh in.