Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7846e33

Browse files
committedNov 1, 2023
[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`
1 parent 6743aef commit 7846e33

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed
 

‎nvm.sh

+25-17
Original file line numberDiff line numberDiff line change
@@ -756,23 +756,31 @@ nvm_normalize_lts() {
756756
local LTS
757757
LTS="${1-}"
758758

759-
if [ "$(expr "${LTS}" : '^lts/-[1-9][0-9]*$')" -gt 0 ]; then
760-
local N
761-
N="$(echo "${LTS}" | cut -d '-' -f 2)"
762-
N=$((N+1))
763-
local NVM_ALIAS_DIR
764-
NVM_ALIAS_DIR="$(nvm_alias_path)"
765-
local RESULT
766-
RESULT="$(command ls "${NVM_ALIAS_DIR}/lts" | command tail -n "${N}" | command head -n 1)"
767-
if [ "${RESULT}" != '*' ]; then
768-
nvm_echo "lts/${RESULT}"
769-
else
770-
nvm_err 'That many LTS releases do not exist yet.'
771-
return 2
772-
fi
773-
else
774-
nvm_echo "${LTS}"
775-
fi
759+
case "${LTS}" in
760+
lts/-[123456789] | lts/-[123456789][0123456789]*)
761+
local N
762+
N="$(echo "${LTS}" | cut -d '-' -f 2)"
763+
( N=$(( N+1)) ; ) 2>/dev/null
764+
# shellcheck disable=SC2181
765+
if [ $? -ne 0 ]; then
766+
nvm_echo "${LTS}"
767+
return 0
768+
fi
769+
local NVM_ALIAS_DIR
770+
NVM_ALIAS_DIR="$(nvm_alias_path)"
771+
local RESULT
772+
RESULT="$(command ls "${NVM_ALIAS_DIR}/lts" | command tail -n "${N}" | command head -n 1)"
773+
if [ "${RESULT}" != '*' ]; then
774+
nvm_echo "lts/${RESULT}"
775+
else
776+
nvm_err 'That many LTS releases do not exist yet.'
777+
return 2
778+
fi
779+
;;
780+
*)
781+
nvm_echo "${LTS}"
782+
;;
783+
esac
776784
}
777785

778786
nvm_ensure_version_prefix() {

0 commit comments

Comments
 (0)
Please sign in to comment.