Automation · Bash Automation
Bash Fundamentals
Cheat sheet · https://pcornel.dk/topic.php?topic=5277
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 modeshellcheck script.sh— lintbash -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
| Layer | Bash Automation → Bash Fundamentals operational reference |
|---|---|
| Runtime/ownership | GNU Bash shell automation · identify controller/parser, durable intent, identity and target ownership before mutation |
| Persistent intent | Versioned definition/configuration with explicit dependencies, scope and credential boundary |
| Verification | bash -n script.sh && bash -u -o pipefail script.sh --fixture; printf 'exit=%s |
| Expected interpretation | The script parses cleanly, handles quoting/expansion intentionally, propagates pipeline/command failures according to policy, uses explicit inputs and exits with documented status. |
| Recovery boundary | Preserve 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