ch09 · operator · 90-120 min

automation with shell

Write small shell automation that is readable, quoted, checked, and disposable.

You can automate repetitive terminal work without hiding failures.

shellscriptsquotingloopsautomation
Teaching diagramch09 · mental model
three layers of safe automation data "$var" quote to keep intact iteration find -print0 | xargs -0 null-delimited names action set -euo pipefail check, print, fail closed leak: word splitting + glob expansion silently corrupt arguments before the action runs exit nonzero, leave evidence

shows: The three safety layers of small shell automation — quoting data, null-safe iteration, and guarded action — and how unquoted or unsplit input leaks corruption into the action stage.

does not prove: It is a model, not a guarantee: set -euo pipefail and quoting reduce common failure classes but do not prove a given script is correct or safe on every input.

Lessons in this chapter

  1. ch09/l01 Variables and quoting "$var" Keep data intact as it moves through the shell.
  2. ch09/l02 Loops, find, and xargs xargs -0 Use null-safe file lists when automation touches filenames.
  3. ch09/l03 Script guardrails set -euo pipefail Make small scripts fail loudly and leave useful evidence.
capstone

safe automation runbook

Write a small script that scans a disposable log tree, writes a report, and refuses unsafe paths.

Deliverable

Script, sample output, and failure transcript for an unsafe path.

Success criteria

  • Variables are quoted.
  • File iteration is null-safe.
  • Failures are visible and intentional.
Terminal Drill companion

Terminal Basics

After your script handles spaces, exits on failure, and prints useful evidence.

Train after the lesson