Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbenv install: fix substituting $HOME with "~" #2501

Merged
merged 3 commits into from
Jan 21, 2025
Merged

Conversation

mislav
Copy link
Member

@mislav mislav commented Jan 21, 2025

When a version to install was not found, rbenv install is supposed to print instructions like:

$ rbenv install 9.9.9
...
If the version you need is missing, try upgrading ruby-build:

  git -C ~/.rbenv/plugins/ruby-build pull

Note how we want $HOME to be printed as ~ for readability. This used to work in older bash versions but ceased to work in newer bash.

Depending on bash version, the expression ${var/$HOME\//~/} will not have effect because the "~" character in the replacement expression is expanded.

The updated approach is a bit of a mouthful, but it avoids using "~" in a substitution pattern, while also guarding against values of HOME that are blank, values that contain special substitution characters such as *, or when HOME is literally just /.

Depending on bash version, the expression `${var/$HOME\//~/}` will not have
effect because the "~" character in the replacement expression is expanded.

The updated approach is a bit of a mouthful, but it avoids using "~" in a
substitution pattern, while also guarding against values of HOME that are
blank or when HOME is literally just "/".
@mislav mislav merged commit fdcfac8 into master Jan 21, 2025
6 checks passed
@mislav mislav deleted the home-substitution branch January 21, 2025 21:11
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.

1 participant