Skip to content

Add example pair for trap-quoting (SC2064) #7

Description

@posidoni

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

task ci

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions