[Fix] `nvm_normalize_lts`: switch from expr to case

avoids `expr: warning: ^lts/-[1-9][0-9]*: using ^ as the first character of a basic regular expression is not portable; it is ignored`
Jordan Harband 2023-11-01 12:24:29 -07:00
parent 6743aef70c
commit 1f970ccb7a
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
1 changed files with 25 additions and 17 deletions

42
nvm.sh
View File

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