Skip to content

Fix "unbound variable" error when running terraform with no args - #539

Open
richadr wants to merge 2 commits into
tfutils:masterfrom
richadr:fix/no-args-unbound-variable
Open

Fix "unbound variable" error when running terraform with no args#539
richadr wants to merge 2 commits into
tfutils:masterfrom
richadr:fix/no-args-unbound-variable

Conversation

@richadr

@richadr richadr commented Aug 30, 2026

Copy link
Copy Markdown

Description

If you run terraform with no arguments, you get this:

/opt/homebrew/Cellar/tfenv/3.2.2/lib/tfenv-exec.sh: line 31: @: unbound variable

The bug was introduced in 0bd45d1

On macOS Bash 3.2 with set -u, braced "${@}" is treated as unset when there are no positional parameters, so terraform (no args) dies with @: unbound variable. Unbraced "$@" and the slice "${@:1}" do not. terraform plan already worked because @ was set.

The fix was mentioned in #532 (comment) and I added a test on top of it.

Issue Link

Closes #532

Testing

  • Ran ./test/run.sh locally and all tests pass
  • Tested on at least one platform (note which below)
  • New tests added for new functionality (if applicable)

Platform tested:

macOS 26.6.2 (25G83)

Quality Checklist

  • Shell quoting verified — all variables quoted, braces used
  • Cross-platform considered — BSD vs GNU tool differences
  • No unintended changes to other commands
  • README.md updated (if user-facing change)
  • CHANGELOG.md updated (if notable change)

@richadr
richadr requested a review from Zordrak as a code owner August 30, 2026 11:55
On macOS Bash 3.2 with set -u, braced "${@}" is treated as unset when
there are no positional parameters, so terraform (no args) dies with
@: unbound variable. ${@+"$@"} expands to nothing in that case.
@richadr
richadr force-pushed the fix/no-args-unbound-variable branch from 9696719 to 5d03333 Compare August 30, 2026 12:00
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.

/opt/homebrew/Cellar/tfenv/3.2.2/lib/tfenv-exec.sh: line 31: @: unbound variable

1 participant