What's wrong
examples/bash/04-nullglob-empty-match.bad.sh defines mktemp -d and
trap 'rm -rf "$tmp"' EXIT inside the main() ( ... ) subshell:
main() (
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
cd "$tmp"
for file in *.txt; do
printf 'found: %s\n' "$file"
done
)
Under Bash 3.2 — which macOS ships by default and which this repo's
shell-macos CI job explicitly targets — an EXIT trap defined inside a
subshell (...) does not fire when the subshell exits. The temp directory
is created but never cleaned up, leaking on every run (including every CI run
of tests/examples.bats on the macOS job).
Flagged by gemini-code-assist on PR #12, and already fixed on the paired
.good.sh in the same PR (see the merged commit) by hoisting tmp/trap to
global scope:
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
main() (
cd "$tmp"
...
)
What to do
Apply the identical hoist to examples/bash/04-nullglob-empty-match.bad.sh
so both files in the pair use the same (correct) temp-dir/trap scope. No
behavioral change to the demonstrated pitfall (the unmatched-glob-stays-literal
behavior is unaffected) — this is purely a cleanup/portability fix.
Verify
must stay green.
What's wrong
examples/bash/04-nullglob-empty-match.bad.shdefinesmktemp -dandtrap 'rm -rf "$tmp"' EXITinside themain() ( ... )subshell:Under Bash 3.2 — which macOS ships by default and which this repo's
shell-macosCI job explicitly targets — anEXITtrap defined inside asubshell
(...)does not fire when the subshell exits. The temp directoryis created but never cleaned up, leaking on every run (including every CI run
of
tests/examples.batson the macOS job).Flagged by
gemini-code-assiston PR #12, and already fixed on the paired.good.shin the same PR (see the merged commit) by hoistingtmp/traptoglobal scope:
What to do
Apply the identical hoist to
examples/bash/04-nullglob-empty-match.bad.shso both files in the pair use the same (correct) temp-dir/trap scope. No
behavioral change to the demonstrated pitfall (the unmatched-glob-stays-literal
behavior is unaffected) — this is purely a cleanup/portability fix.
Verify
must stay green.