diff --git a/nvm.sh b/nvm.sh index 8204b6d9..17d36c4f 100755 --- a/nvm.sh +++ b/nvm.sh @@ -3672,14 +3672,18 @@ nvm() { if [ "${-#*e}" != "$-" ]; then set +e local EXIT_CODE - IFS="${DEFAULT_IFS}" nvm "$@" + local IFS + IFS="${DEFAULT_IFS}" + nvm "$@" EXIT_CODE="$?" set -e return "$EXIT_CODE" elif [ "${-#*a}" != "$-" ]; then set +a local EXIT_CODE - IFS="${DEFAULT_IFS}" nvm "$@" + local IFS + IFS="${DEFAULT_IFS}" + nvm "$@" EXIT_CODE="$?" set -a return "$EXIT_CODE" @@ -3687,13 +3691,17 @@ nvm() { # shellcheck disable=SC3041 set +E local EXIT_CODE - IFS="${DEFAULT_IFS}" nvm "$@" + local IFS + IFS="${DEFAULT_IFS}" + nvm "$@" EXIT_CODE="$?" # shellcheck disable=SC3041 set -E return "$EXIT_CODE" elif [ "${IFS}" != "${DEFAULT_IFS}" ]; then - IFS="${DEFAULT_IFS}" nvm "$@" + local IFS + IFS="${DEFAULT_IFS}" + nvm "$@" return "$?" fi diff --git a/test/fast/Running 'nvm' should not change or export the caller's IFS b/test/fast/Running 'nvm' should not change or export the caller's IFS new file mode 100755 index 00000000..07a4cbb0 --- /dev/null +++ b/test/fast/Running 'nvm' should not change or export the caller's IFS @@ -0,0 +1,19 @@ +#!/bin/sh + +die () { IFS=' '; echo "$@" ; exit 1; } + +: nvm.sh +\. ../../nvm.sh + +IFS=':' +nvm --version >/dev/null +[ "${IFS}" = ':' ] || die "nvm changed the caller's IFS; got >${IFS}<" + +set -e +nvm --version >/dev/null +set +e +[ "${IFS}" = ':' ] || die "nvm changed the caller's IFS under set -e; got >${IFS}<" + +! env | grep -q '^IFS=' || die 'nvm exported IFS' + +IFS=' '