Skip to content

Fix RVM loading with bash nounset#5657

Open
ZiPengWei wants to merge 1 commit into
rvm:masterfrom
ZiPengWei:codex/fix-bash-nounset-loading
Open

Fix RVM loading with bash nounset#5657
ZiPengWei wants to merge 1 commit into
rvm:masterfrom
ZiPengWei:codex/fix-bash-nounset-loading

Conversation

@ZiPengWei

Copy link
Copy Markdown

Summary

Fixes #4694.

This makes the RVM load path tolerate Bash set -u/nounset when no system metadata has been detected yet. The failing Packer/AWS scenario runs RVM from a strict-mode shell, so reads of variables such as _system_name, rvm_prefix, and chpwd_functions should not assume those names have already been initialized.

Changes:

  • Guard rvm_prefix before deriving it from rvm_path.
  • Fall back to the generic utility setup before _system_name has been detected.
  • Initialize and append to chpwd_functions without triggering nounset on Bash 3.2.
  • Add a fast regression test for sourcing RVM and selecting the system Ruby under nounset.

Validation

  • bash -n scripts/rvm scripts/functions/support scripts/cd tests/fast/nounset_comment_test.sh
  • bash -lc 'set -u; export rvm_path=$PWD; source scripts/rvm; rvm use system >/tmp/rvm-use-system.out; cat /tmp/rvm-use-system.out; declare -p chpwd_functions; [[ ":${SHELLOPTS:-}:" == *":nounset:"* ]]'
  • bash -lc 'set -u; export rvm_path=$PWD; source scripts/rvm; rvm info system >/tmp/rvm-info-system.out; head -n 22 /tmp/rvm-info-system.out; [[ ":${SHELLOPTS:-}:" == *":nounset:"* ]]'
  • git diff --check

Note: the local rvm info system run on macOS emits existing environment warnings about /opt/homebrew/bin permissions and Command Line Tools vs full Xcode, but exits successfully.

Signed-off-by: 魏子堋 <506837925@qq.com>
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.

RVM 1.29.8 throwing "_system_name: unbound variable" error on AWS under Packer

1 participant