Skip to content

Fix operator precedence bug and unbound variable in tfenv-version-name.sh#461

Merged
Zordrak merged 1 commit intomasterfrom
fix/406-431-version-name-bugs
Apr 24, 2026
Merged

Fix operator precedence bug and unbound variable in tfenv-version-name.sh#461
Zordrak merged 1 commit intomasterfrom
fix/406-431-version-name-bugs

Conversation

@Zordrak
Copy link
Copy Markdown
Collaborator

@Zordrak Zordrak commented Apr 24, 2026

Summary

Two bugs fixed in lib/tfenv-version-name.sh:

1. Shell operator precedence bug (line 13) — Fixes #431, #447

Before:

TFENV_VERSION="$(cat "${TFENV_VERSION_FILE}" || true | tr -d '\r')"

Due to shell precedence, || binds cat to true, making the pipeline cat ... || (true | tr ...). The tr -d '\r' only runs on the failure path. When cat succeeds (the normal case), carriage returns are never stripped.

After:

TFENV_VERSION="$(cat "${TFENV_VERSION_FILE}" | tr -d '\r' || true)"

tr is now always in the pipeline. The || true ensures the overall command does not fail if the file is missing.

This fixes the root cause of #431 (trailing whitespace breaking version resolution) and #447 (WSL/Windows carriage returns causing garbled output).

2. Undefined variable in error message (line 82) — Fixes #406

Before:

log 'error' "No versions matching '${requested}' found in remote";

${requested} was never defined in this scope, causing an unbound variable crash under set -u before the error message could be displayed.

After:

log 'error' "No versions matching '${TFENV_VERSION}' found in remote";

Testing

  • Ran ./test/run.sh test_install_and_use.sh on Linux (Ubuntu) — 41/41 tests pass, 0 failures.
  • Cross-platform CI will validate macOS via the PR workflow.

…e.sh

Fix #406: Replace undefined ${requested} variable with ${TFENV_VERSION}
in the error message on line 82. The variable was introduced in commit
3dc5819 but never existed in scope, causing an unbound variable crash
under set -u before the error message could be displayed.

Fix #431: Fix shell operator precedence in the version file read on
line 13. The original "cat ... || true | tr" meant tr only ran on the
failure path due to || binding tighter than |. Restructured to
"cat ... | tr ... || true" so carriage returns are always stripped.

Also addresses #447 (WSL carriage return symptoms) which shares the
same root cause as #431.
@Zordrak Zordrak merged commit 4a703e8 into master Apr 24, 2026
5 checks passed
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.

Trailing whitespace breaks version resolution Unbound variable error in error message

1 participant