Pcornel
Automation · Bash Automation

Bash Fundamentals

Cheat sheet · https://pcornel.dk/topic.php?topic=5277

Back to the Topic

Answer

Bash fundamentals: scripts start with #!/usr/bin/env bash, use set -euo pipefail for safety, quote variables ("$var"), check exit codes and are made executable with chmod +x.

Remember

  • Start with #!/usr/bin/env bash and set -euo pipefail.
  • Quote every variable expansion: "$var".
  • Check commands' exit codes.

First checks

  • head -3 script.sh — shebang and strict mode
  • shellcheck script.sh — lint
  • bash -x script.sh — trace

Verify in this order

script → bash interpreter → commands

Where it usually breaks

Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.

Bash Automation → Bash Fundamentals · operational reference

LayerBash Automation → Bash Fundamentals operational reference
Runtime/ownershipGNU Bash shell automation · identify controller/parser, durable intent, identity and target ownership before mutation
Persistent intentVersioned definition/configuration with explicit dependencies, scope and credential boundary
Verificationbash -n script.sh && bash -u -o pipefail script.sh --fixture; printf 'exit=%s
Expected interpretationThe script parses cleanly, handles quoting/expansion intentionally, propagates pipeline/command failures according to policy, uses explicit inputs and exits with documented status.
Recovery boundaryPreserve correlation IDs + pre-state, repair first failing boundary, then verify the target independently

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5277

Confirmation

Confirm action

Continue?