Skip to content

Commit

Permalink
[Fix] nvm_normalize_lts: switch from expr to case
Browse files Browse the repository at this point in the history
avoids `expr: warning: ^lts/-[1-9][0-9]*: using ^ as the first character of a basic regular expression is not portable; it is ignored`
  • Loading branch information
ljharb committed Nov 1, 2023
1 parent 6743aef commit fbc7511
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -756,23 +756,26 @@ nvm_normalize_lts() {
local LTS
LTS="${1-}"

if [ "$(expr "${LTS}" : '^lts/-[1-9][0-9]*$')" -gt 0 ]; then
local N
N="$(echo "${LTS}" | cut -d '-' -f 2)"
N=$((N+1))
local NVM_ALIAS_DIR
NVM_ALIAS_DIR="$(nvm_alias_path)"
local RESULT
RESULT="$(command ls "${NVM_ALIAS_DIR}/lts" | command tail -n "${N}" | command head -n 1)"
if [ "${RESULT}" != '*' ]; then
nvm_echo "lts/${RESULT}"
else
nvm_err 'That many LTS releases do not exist yet.'
return 2
fi
else
nvm_echo "${LTS}"
fi
case "${LTS}" in
lts/-[123456789] | lts/-[123456789][0123456789]*)
local N
N="$(echo "${LTS}" | cut -d '-' -f 2)"
N=$((N+1))
local NVM_ALIAS_DIR
NVM_ALIAS_DIR="$(nvm_alias_path)"
local RESULT
RESULT="$(command ls "${NVM_ALIAS_DIR}/lts" | command tail -n "${N}" | command head -n 1)"
if [ "${RESULT}" != '*' ]; then
nvm_echo "lts/${RESULT}"
else
nvm_err 'That many LTS releases do not exist yet.'
return 2
fi
;;
*)
nvm_echo "${LTS}"
;;
esac
}

nvm_ensure_version_prefix() {
Expand Down

0 comments on commit fbc7511

Please sign in to comment.