Manuals / Linux Shell Daily / Ch 3

CoreIntermediate35 min read

3. Exit codes & scripts

Linux Shell Daily · 12 pages source format

$? and simple bash scripts for repetitive checks.

What you'll learn

  • Exit codes
  • set -e
  • Tiny scripts

Key idea

0 means success; non-zero means failure — CI depends on this.

Quick check

Exit code 0 usually means…

Do this now

Write 3 notes on: Exit codes.

Clear?

Practice

Write a 10-line script that greps a log and exits 1 if errors exist.

Starter
#!/usr/bin/env bash
set -euo pipefail
grep -q ERROR "$1" && exit 1 || exit 0

Do this now

Commit one file practicing Exit codes.

Clear?

Checklist