What's missing
reference/shell-standards.md rule 9
("Clean up with trap on EXIT") explains that a trap command must be
single-quoted so the cleanup expression is evaluated when the signal fires,
not when trap is registered. Unlike every other rule in that doc, rule 9
has no runnable pair under examples/standards/
proving it.
Verified locally with ShellCheck 0.11.0:
$ shellcheck --severity=style --format=gcc t.sh
t.sh:4:14: warning: Use single quotes, otherwise this expands now rather than when signalled. [SC2064]
What to do
Add examples/standards/11-trap-single-quote.good.sh and .bad.sh,
following the contract in
CONTRIBUTING.md:
.good.sh — creates a temp dir with mktemp -d, sets
trap 'rm -rf "$tmp"' EXIT (single-quoted), self-contained, exits 0,
clean under shellcheck --severity=warning and shfmt.
.bad.sh — the same pattern but double-quoted
(trap "rm -rf $tmp" EXIT), safe to run, with
# expect-shellcheck: SC2064.
- Add a row to the table in
examples/standards/README.md.
Verify
must stay green — tools/check-bad-examples.sh asserts the new .bad.sh
actually triggers SC2064, and tests/examples.bats runs the new
.good.sh.
What's missing
reference/shell-standards.mdrule 9("Clean up with
traponEXIT") explains that atrapcommand must besingle-quoted so the cleanup expression is evaluated when the signal fires,
not when
trapis registered. Unlike every other rule in that doc, rule 9has no runnable pair under
examples/standards/proving it.
Verified locally with ShellCheck 0.11.0:
What to do
Add
examples/standards/11-trap-single-quote.good.shand.bad.sh,following the contract in
CONTRIBUTING.md:
.good.sh— creates a temp dir withmktemp -d, setstrap 'rm -rf "$tmp"' EXIT(single-quoted), self-contained, exits 0,clean under
shellcheck --severity=warningandshfmt..bad.sh— the same pattern but double-quoted(
trap "rm -rf $tmp" EXIT), safe to run, with# expect-shellcheck: SC2064.examples/standards/README.md.Verify
must stay green —
tools/check-bad-examples.shasserts the new.bad.shactually triggers
SC2064, andtests/examples.batsruns the new.good.sh.