Bash and shell · zero to on-call
Scripts that do not surprise you at 3 a.m.
Quoting, exit codes, pipes and traps, with an X-ray that finds what will break before it runs, and a bash playground full of real incidents.
Learning shell scripting?
Start from zero, step by step.
Levels in order, each with a hands-on incident to fix in your browser.
Something broken right now?
Paste the error, get the fix.
The cause, the commands to confirm it and the fix, for every common bash error.
Everything you need, from the first script to the 3 a.m. incident.
Fix a broken script. Right here.
A bash shell over a small server, with real error messages. Run the script, edit it, run it again.
Practise on your own machine
Get the scripts
Bash 4 or later, on Linux, macOS (brew install bash) or WSL.
# 1. Get the course
git clone https://github.com/SandeepKomal/Shell.git
cd Shell
# 2. Run the tests: the scripts in throwaway folders
tests/test_scripts.sh
# 3. Try one
./scripts/check_disk_usage.sh 80
Check your own scripts
The habits this course builds, in four commands.
bash -n script.sh # syntax
shellcheck script.sh # lint
bash -x script.sh # trace
env -i HOME="$HOME" PATH=/usr/bin:/bin ./script.sh # as cron
Or paste it into the Script X-ray. Look up any error in Troubleshoot.
Your path
Progress is saved in this browser only. Tick a level when you have done its lab.
Quiz
Scenario questions for every level: predict what bash does. You see right or wrong as soon as you answer, with the reasoning.
Scripts
Every script in the repository, tested and ready to use: what it is for, how to run it, what it prints and what its exit status means. Anything that changes or deletes is a dry run until you add -y.
Script X-ray
Paste a shell script to see what every line does, which lines are risky and why, and what is missing.
Stuck on an error?
Paste the error bash printed, or describe the symptom. Each answer explains why it happens, how to confirm it and how to fix and prevent it, then gives you a safe scenario to break and fix it yourself, so you recognise it next time.
Also as one plain page: every bash error, explained.
Cheat sheet
The commands and idioms scripts use most. Try runs one in the playground, in the scenario where it makes sense. Lab marks the few that need a real system.
How bash runs a command
From a line of text to running programs: what bash does, in order, and what goes wrong at each step. Type a command line to watch it go through.