Pcornel
Automation · Scripting

Variables

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

Back to the Topic

Answer

Variables hold runtime values and state inside a script; reliable use requires clear scope, type/shape expectations, initialization, lifetime and protection of sensitive values.

Remember

  • Variable assigned ≠ value valid; a non-empty value can still be malformed, stale or unauthorized.
  • Global availability ≠ correct ownership; wide scope increases coupling and hidden side effects.
  • String representation ≠ semantic type; numeric, boolean, date and structured values require deliberate parsing.
  • Secret stored in a variable ≠ secret protected; process memory, debug output and child-process inheritance may expose it.

First checks

  • shellcheck script.sh (SC2086 unquoted) — quoting
  • declare -p <var> — inspect Bash variable
  • Get-Variable <name> — PowerShell

Verify in this order

value → variable → used safely

Where it usually breaks

A variable containing a value proves only that data is present in memory; it does not prove origin, validity, freshness, authorization or correctness for the downstream action.

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

Variables 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=5214

Confirmation

Confirm action

Continue?