From accd6ae2987c17a32621af827579393d33dcb80e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 28 Apr 2017 00:39:48 -0700 Subject: [PATCH] [Fix] ensure if `npm link` fails, that `$IFS` is not improperly set. https://github.com/creationix/nvm/issues/1519#issuecomment-297850323 --- nvm.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/nvm.sh b/nvm.sh index 1ae752f..5529f59 100644 --- a/nvm.sh +++ b/nvm.sh @@ -3157,15 +3157,16 @@ nvm() { nvm_echo "$INSTALLS" | command xargs npm install -g --quiet nvm_echo "Linking global packages from $VERSION..." - set -f; IFS=' + ( + set -f; IFS=' ' # necessary to turn off variable expansion except for newlines - for LINK in $LINKS; do - set +f; unset IFS # restore variable expansion - if [ -n "$LINK" ]; then - (nvm_cd "$LINK" && npm link) - fi - done - set +f; unset IFS # restore variable expansion in case $LINKS was empty + for LINK in $LINKS; do + set +f; unset IFS # restore variable expansion + if [ -n "$LINK" ]; then + (nvm_cd "$LINK" && npm link) + fi + done + ) ;; "clear-cache" ) command rm -f "$NVM_DIR/v*" "$(nvm_version_dir)" 2>/dev/null