Pcornel
Automation · Bash Automation

Conditions

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

Back to the Topic

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

LayerBash Automation → Conditions operational reference
Context identityGNU Bash 5.3/current + exact revision/input/target identity
Persistent intentVersioned contract/configuration with explicit ownership and prerequisites
VerificationValidate inputs/read current state → exercise bounded operation → independent target read-back
Output contractPreserve structured status/IDs/properties before human formatting
Failure boundarySeparate 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

Confirmation

Confirm action

Continue?