Kolam Ayer MakersLinux Foundations

Control Flow

Core Idea

Control flow is how a shell program chooses what happens next.

Without control flow, a script is just a fixed list of commands. With control flow, scripts can branch on success, repeat work, and stop when checks fail.

Main Tools

Example

if [[ -f ~/src/pages/index.md ]]; then
  printf 'source exists\n'
else
  printf 'missing source\n' >&2
  exit 1
fi

Watch Out

Readable control flow beats clever control flow. If the command is hard to explain, make it a script with clear lines.

Docs Pointers