Context
reference/shell-standards.md rule 17
("Fail fast on a required variable with ${var:?message}") has no runnable
pair under examples/standards/. Follow the contract
in CONTRIBUTING.md.
Plan
- Add
examples/standards/13-fail-fast-required-var.good.sh:
- Guard a required variable with
: "${VAR:?message}" before using it in
a path or command, so a missing/empty value aborts immediately with a
clear message on stderr.
- Self-contained (set the variable directly in the script so it runs to
completion), no arguments, exits 0, clean under
shellcheck --severity=warning and shfmt. Use mktemp -d + a trap
for any filesystem work.
- Add
examples/standards/13-fail-fast-required-var.bad.sh:
- Use the same variable unchecked (e.g. leave it defaulted to empty via
: "${VAR:=}") so an empty value silently builds a broken path instead
of failing.
- Safe to run — keep every path inside the
mktemp -d sandbox so an empty
variable can never touch anything outside it.
# expect-shellcheck: none — this is a style-guide-only pitfall,
ShellCheck cannot detect a missing fail-fast check.
- Add a row to the table in
examples/standards/README.md.
Verify
must stay green.
A small ask
If you used an AI coding agent for this PR, feel free to say so — add a line
to the PR description like:
Authored by <your name/handle>, implemented using <model name>.
Either way is genuinely welcome here.
Context
reference/shell-standards.mdrule 17("Fail fast on a required variable with
${var:?message}") has no runnablepair under
examples/standards/. Follow the contractin CONTRIBUTING.md.
Plan
examples/standards/13-fail-fast-required-var.good.sh:: "${VAR:?message}"before using it ina path or command, so a missing/empty value aborts immediately with a
clear message on stderr.
completion), no arguments, exits 0, clean under
shellcheck --severity=warningandshfmt. Usemktemp -d+ atrapfor any filesystem work.
examples/standards/13-fail-fast-required-var.bad.sh:: "${VAR:=}") so an empty value silently builds a broken path insteadof failing.
mktemp -dsandbox so an emptyvariable can never touch anything outside it.
# expect-shellcheck: none— this is a style-guide-only pitfall,ShellCheck cannot detect a missing fail-fast check.
examples/standards/README.md.Verify
must stay green.
A small ask
If you used an AI coding agent for this PR, feel free to say so — add a line
to the PR description like:
Either way is genuinely welcome here.