Pcornel
Automation · Scripting

Conditions

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

Back to the Topic

Answer

Conditions turn observed state into branch decisions. Reliable scripting requires conditions to use normalized inputs, explicit comparison semantics and safe handling of unknown or ambiguous state.

Remember

  • Condition true ≠ action safe; authorization, scope and current target state may still block the action.
  • Falsy/empty ≠ absent automatically; language coercion can collapse valid values such as zero or empty collections.
  • String equality ≠ semantic equality; case, whitespace, locale, versions and numeric parsing can change meaning.
  • No matching branch ≠ success; unexpected state should be handled explicitly rather than fall through silently.

First checks

  • [[ -f /path ]] && echo yes — Bash test
  • if (Test-Path C:\path) { 'yes' } — PowerShell
  • Explicit else branches — handling

Verify in this order

condition → branch

Where it usually breaks

A condition result proves only how the script interpreted a specific value at that moment; it does not prove the resulting action is authorized, safe or successful.

Script/input → command/module binding → local/remoting session → request accepted → command result → target object read-back → effective runtime state → workload.

Conditions scripting boundary map

BoundaryHealthy evidenceSuspicious evidence
Input / runtimeEffective inputs, runtime, working context and dependency versions are explicitHidden defaults, stale environment, wrong interpreter/path or unvalidated input
Logic / executionBranch/function/module decisions and external actions expose per-operation resultsSwallowed failures, shell reinterpretation, blind retries or last-result-wins behavior
Result / proofExit/exception/log evidence is correlated with independent target read-backProcess success or printed output treated as target success
Recovery / troubleshootingFirst failed boundary is preserved, changed minimally and retestedRandom edits, catch-all suppression or evidence destroyed before diagnosis

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

Confirmation

Confirm action

Continue?