Kolam Ayer MakersLinux Foundations

Shell Scripting

Core Idea

A shell script is a file of commands that Bash can run repeatably.

Like any command, a script returns an exit status. 0 means success. Nonzero means failure. Good scripts print useful text and return the right status.

Practice Alone

Start with a shebang, add set -euo pipefail, then run the script with bash.

bash ~/scripts/hello.sh Ada
printf '%s\n' "$?"
bash ~/scripts/hello.sh
printf '%s\n' "$?"

The success path and the failure path should return different statuses.

Done When

Your script works twice in a row without manual fixes.

It also fails clearly when required input is missing.

Go Deeper