Skip to content

fix: guard empty array expansion for bash 3.2 compatibility#791

Closed
tairosonloa wants to merge 2 commits intotw93:mainfrom
tairosonloa:fix/issue-790
Closed

fix: guard empty array expansion for bash 3.2 compatibility#791
tairosonloa wants to merge 2 commits intotw93:mainfrom
tairosonloa:fix/issue-790

Conversation

@tairosonloa
Copy link
Copy Markdown

@tairosonloa tairosonloa commented Apr 25, 2026

Summary

macOS ships with bash 3.2, which raises "unbound variable" under set -u when expanding an empty array with "${array[@]}", even if the array was declared with local -a array=().

This PR uses the ${array[@]+"${array[@]}"} idiom so the expansion is skipped safely when mapped_app_bundles is empty.

Fixes: #790

Safety Review

  • Does this change affect cleanup, uninstall, optimize, installer, remove, analyze delete, update, or install behavior?

Yes, as it fixes an issue with mo clean

  • Does this change affect path validation, protected directories, symlink handling, sudo boundaries, or release/install integrity?

No

  • If yes, describe the new boundary or risk change clearly.

N/A

Tests

  • List the automated tests you ran.

I ran the related test suite with bats tests/bundle_resolver.bats

  • List any manual checks for high-risk paths or destructive flows.

N/A, but I tested to run the mo clean again on my MacBook and the error is now gone.

Safety-related changes

  • None.

macOS ships with bash 3.2, which raises "unbound variable" under `set -u`
when expanding an empty array with `"${array[@]}"`, even if the array was
declared with `local -a array=()`. Use the `${array[@]+"${array[@]}"}` idiom
so the expansion is skipped safely when `mapped_app_bundles` is empty.

Related with tw93#790
@tairosonloa tairosonloa requested a review from tw93 as a code owner April 25, 2026 15:58
Adds a test that exercises the empty mapped_app_bundles array expansion under set -euo pipefail with multiple apps to scan, asserting a clean exit status 1 instead of crashing with "unbound variable" in bash 3.2.
@tw93
Copy link
Copy Markdown
Owner

tw93 commented Apr 26, 2026

@tairosonloa thanks for catching this fast and including a regression test. There was an overlapping PR (#792) using the explicit (( ${#arr[@]} > 0 )) length-check guard, which fits this codebase's defensive-shell style a bit better, so I went with that one. Really appreciate the report, your test logic is the same and your fix would have worked equally well.

Closing this PR. The fix will ship in the next release; you can run mo update --nightly to install the latest code version once it's tagged.

@tw93 tw93 closed this Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Unbound variable error in bundle_resolver.sh during 'mo clean' app leftovers scan

2 participants