Automation · Bash Automation
Conditions
Cheat sheet · https://pcornel.dk/topic.php?topic=5279
Answer
Bash conditions use if with [[ ]] for tests on strings, numbers and files, such as [[ -f $file ]] or [[ $n -gt 5 ]], plus case for matching patterns.
Remember
- Use [[ ]] for tests.
- -f file, -d dir, -z empty, -eq numbers.
- case for pattern matching.
First checks
[[ -n "$var" ]] && echo set— string test[[ -f /path ]]— file test(( count > 5 ))— arithmetic test
Commands
test
Verify in this order
condition → branch
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 → Conditions · operational reference
| Layer | Bash Automation → Conditions operational reference |
|---|---|
| Context identity | GNU Bash 5.3/current + exact revision/input/target identity |
| Persistent intent | Versioned contract/configuration with explicit ownership and prerequisites |
| Verification | Validate inputs/read current state → exercise bounded operation → independent target read-back |
| Output contract | Preserve structured status/IDs/properties before human formatting |
| Failure boundary | Separate source/input/engine/controller execution from downstream target outcome |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5279