Skip to content
Prev Previous commit
fix: guard empty _CLEANUP_FILES array for Bash 3.2 compatibility
On Bash 3.2, the ${arr[@]+"${arr[@]}"} pattern expands to a single
empty string when the array is empty, causing rm to target .bak and
.tmp in the current directory. Use explicit length check instead,
which also avoids the word-splitting risk of unquoted expansion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
  • Loading branch information
Bo Bobson and claude committed Apr 7, 2026
commit aac7864734beea7dfe92c2408bd4ca825a1a4356
8 changes: 5 additions & 3 deletions scripts/bash/update-agent-context.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ cleanup() {
local exit_code=$?
# Disarm traps to prevent re-entrant loop
trap - EXIT INT TERM
for f in "${_CLEANUP_FILES[@]+"${_CLEANUP_FILES[@]}"}"; do
rm -f "$f" "$f.bak" "$f.tmp"
done
if [ ${#_CLEANUP_FILES[@]} -gt 0 ]; then
for f in "${_CLEANUP_FILES[@]}"; do
rm -f "$f" "$f.bak" "$f.tmp"
done
fi
exit $exit_code
}

Expand Down
Loading