Fix #532: terraform shim fails with "@: unbound variable" on Bash 3.2 when run with no arguments - #541
Open
marcleblanc2 wants to merge 1 commit into
Open
Fix #532: terraform shim fails with "@: unbound variable" on Bash 3.2 when run with no arguments#541marcleblanc2 wants to merge 1 commit into
marcleblanc2 wants to merge 1 commit into
Conversation
…ash 3.2 when run with no arguments 0bd45d1 changed the argument loop in tfenv-exec() to `for _arg in "${@}"` to stop word-splitting arguments with spaces (tfutils#453). Under `set -u`, Bash 3.2 (macOS /bin/bash) treats an empty "$@" as an unbound variable, so running the shim with no arguments now aborts before terraform runs. zsh's bashcompinit invokes `complete -C` commands with no arguments, so every tab completion after `terraform` printed only this error. Use `for _arg; do`, which iterates the positional parameters without expanding "$@", so it neither word-splits nor trips `set -u` on any Bash version. Add test/test_exec.sh covering the shim with no arguments (under both `bash` and /bin/bash) and a -chdir path containing a space, and correct the for-loop guidance in AGENTS.md and bash.instructions.md. Amp-Thread-ID: https://ampcode.com/threads/T-01a0eee4-d46a-776d-9873-341f0d5f7fd2 Co-authored-by: Amp <amp@ampcode.com>
Author
|
Hey @Zordrak, is this project active and / or looking for maintainers? It's been a game changer to use. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Under
set -u, Bash 3.2 (macOS/bin/bash) treats an empty"$@"as an unbound variable, so running the shim with no arguments aborts before terraform runs:0bd45d1 changed the argument loop in
tfenv-exec()tofor _arg in "${@}"to stop word-splitting arguments with spaces (#453).zsh's
bashcompinitinvokescomplete -Ccommands with no arguments (it only setsCOMP_LINE/COMP_POINT), so on macOS every tab completion afterterraformprints only this error.The fix uses
for _arg; do, which iterates the positional parameters without expanding"$@". It neither word-splits (keeps #453 fixed) nor tripsset -uon any Bash version, and it is POSIX.Also adds
test/test_exec.shfor the shim and corrects the for-loop guidance inAGENTS.md/.github/instructions/bash.instructions.md, which previously recommended the form that caused this regression.Issue Link
Fixes #532
Testing
./test/run.shlocally;commands,env_vars,exec,install_lock,list,list_remote,pin,resolve_version,symlink,uninstall,use_minrequired,version_filepass.install_and_use,prerelease_filter,use_dash,use_latestallowedfail identically on unmodifiedmasteron this machine withBad CPU type in executable(they install pre-1.0darwin_amd64builds; Apple Silicon without Rosetta), so unrelated to this change.test/test_exec.shbashand/bin/bashmust reach terraform's usage output with nounbound variable(fails onmaster, passes here)terraform '-chdir=chdir-dir/with space' versionmust resolve the version from that directory (fails with the pre-Bug: Unquoted ${@:1} word-splits arguments with spaces in tfenv-exec.sh #453 unquoted${@:1}, passes here)COMP_LINE="terraform pl" COMP_POINT=12 bin/terraformprintsplanwith this branch; the 3.2.2 Homebrew shim prints the unbound-variable error.Platform tested: macOS 26 (arm64), Bash 3.2.57
Quality Checklist
/bin/bashtest iteration is skipped where absent)AGENTS.md