Practical Bash Scripting: Automate Tasks Quickly
Script 1: Hello World and Variables
Run it:
Immediate insight:
-
$NAME→ variable usage -
read -p→ takes user input
Script 2: Looping Through Files
Run it:
Insight:
-
for file in *.txt→ iterates over files matching the pattern -
Useful for batch processing
Script 3: Conditional Logic
Immediate insight:
-
[ -d "$DIR" ]→ checks if a directory exists -
mkdir→ creates directory
Script 4: Simple Backup Script
Run it:
Immediate insight:
-
mkdir -p→ creates folder only if it doesn't exist -
cp→ copies files -
This script can run daily with
cronfor automation
Script 5: Simple Logging
Immediate insight:
-
>>→ append output to a file -
Useful for recording actions or cron jobs
Summary
In this style:
-
You write working scripts first
-
See results immediately
-
Learn by running and modifying