Bash Scripting
Automate repetitive Linux work with Bash: write scripts that take input, make decisions, loop and process data, fail safely and log what they did, then run them on a schedule.
Modules
8
Lessons
56
Level
Beginner
Project
Reviewed by a mentor
About This Course
You already know your way around a Linux terminal. This course teaches you to turn those commands into scripts that make decisions, loop over files, process text and fail safely. You finish by writing a backup script that runs on a schedule and that you have proved you can restore from.
You'll Be Able To
- Turn repetitive terminal work into scripts.
- Write scripts that take input, make decisions and loop over data.
- Write scripts that fail safely, clean up after themselves and log what they did.
- Debug and lint your own scripts.
- Schedule scripts to run unattended.
What's Inside
- 1
Getting started
6 lessons
Write your first Bash scripts: add a shebang, make them executable and readable, run them by name from ~/bin, and know when to use ./, bash or source.
- 2
Variables and input
8 lessons
Store values in variables, quote them safely, capture command output, and get input into scripts through arguments, prompts, environment variables and defaults.
- 3
Making decisions
8 lessons
Make scripts react to what they find: read exit codes, write tests on strings, numbers and files, and choose what to do with if, case, && and ||.
- 4
Loops
6 lessons
Repeat work with loops: go through lists, files and lines of text, wait for a service with a time limit, and control loops with break and continue.
- 5
Functions
5 lessons
Break scripts into functions: pass in arguments, return results through exit codes and output, keep variables local, build around main and share helpers with source.
- 6
Working with data
8 lessons
Handle real data in scripts: arithmetic, arrays and associative arrays, string slicing, grep, sed and awk on logs, JSON with jq, here documents and API calls with curl.
- 7
Reliable scripts
9 lessons
Make scripts safe to run unattended: strict mode, checks before changes, helpful errors and exit codes, clean-up with trap, timestamped logs, set -x, ShellCheck and idempotence.
- 8
Scheduling and automation
6 lessons
Run scripts on a schedule: write cron schedules, install jobs with crontab, fix scripts that fail only under cron, capture output and failures, and use systemd timers.