Code-Memo

Bash scripting fundamentals

Goals

Minimal script template

#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

main() {
  echo "Hello from a script"
}

main "$@"

Core concepts

Useful builtins

Common patterns

Usage + help

usage() { echo "Usage: $0 <path> [--dry-run]" >&2; exit 2; }
[[ $# -ge 1 ]] || usage

Temporary files

tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT

Quick checklist