Pcornel
Automation · Scripting

Scripting Fundamentals

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

Back to the Topic

Answer

Scripting Fundamentals defines the minimum structure of a reliable automation script: explicit entry point, inputs, runtime assumptions, bounded logic, external actions, result semantics and verification.

Remember

  • Readable script ≠ reliable script; structure must expose failure and verification boundaries, not only improve formatting.
  • Main routine completed ≠ every external operation succeeded; child command and API results require explicit handling.
  • Reusable function ≠ safe orchestration; calling order, shared state and side effects still matter.
  • Dry syntax check ≠ runtime validation; environment, permissions, dependencies and target behavior remain unproven.

First checks

  • bash -n script.sh — syntax
  • shellcheck script.sh — lint
  • Header: purpose, usage, author — documentation

Verify in this order

script → interpreter → actions → exit code

Where it usually breaks

A well-structured script improves explainability and failure propagation; it does not prove the business or infrastructure outcome until the external target is checked.

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

Scripting Fundamentals 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=5213

Confirmation

Confirm action

Continue?