Conditions
Cheat sheet · https://pcornel.dk/topic.php?topic=5215
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 testif (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
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Input / runtime | Effective inputs, runtime, working context and dependency versions are explicit | Hidden defaults, stale environment, wrong interpreter/path or unvalidated input |
| Logic / execution | Branch/function/module decisions and external actions expose per-operation results | Swallowed failures, shell reinterpretation, blind retries or last-result-wins behavior |
| Result / proof | Exit/exception/log evidence is correlated with independent target read-back | Process success or printed output treated as target success |
| Recovery / troubleshooting | First failed boundary is preserved, changed minimally and retested | Random 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