From 78a008c3c773d18be9d94aee7350284fe3f30c95 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 6 Jul 2016 15:31:25 -0700 Subject: [PATCH] [Fix] use Solaris-compatible tail options. Fixes #1148. --- nvm.sh | 12 ++++++------ ...nning \"nvm use system\" should work as expected" | 8 ++++---- test/installation_iojs/nvm install v1 works | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/nvm.sh b/nvm.sh index 6ca361a..1b55198 100644 --- a/nvm.sh +++ b/nvm.sh @@ -292,7 +292,7 @@ nvm_version() { PATTERN="stable" ;; esac - VERSION="$(nvm_ls "$PATTERN" | command tail -n1)" + VERSION="$(nvm_ls "$PATTERN" | command tail -1)" if [ -z "$VERSION" ] || [ "_$VERSION" = "_N/A" ]; then nvm_echo "N/A" return 3; @@ -308,14 +308,14 @@ nvm_remote_version() { if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then case "_$PATTERN" in "_$(nvm_iojs_prefix)") - VERSION="$(nvm_ls_remote_iojs | command tail -n1)" + VERSION="$(nvm_ls_remote_iojs | command tail -1)" ;; *) VERSION="$(nvm_ls_remote "$PATTERN")" ;; esac else - VERSION="$(nvm_remote_versions "$PATTERN" | command tail -n1)" + VERSION="$(nvm_remote_versions "$PATTERN" | command tail -1)" fi nvm_echo "$VERSION" if [ "_$VERSION" = '_N/A' ]; then @@ -845,7 +845,7 @@ nvm_ls_remote() { local PATTERN PATTERN="$1" if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then - PATTERN="$(nvm_ls_remote "$(nvm_print_implicit_alias remote "$PATTERN")" | command tail -n1)" + PATTERN="$(nvm_ls_remote "$(nvm_print_implicit_alias remote "$PATTERN")" | command tail -1)" elif [ -n "$PATTERN" ]; then PATTERN="$(nvm_ensure_version_prefix "$PATTERN")" else @@ -1569,9 +1569,9 @@ nvm_npm_global_modules() { local VERSION VERSION="$1" if [ "_$VERSION" = "_system" ]; then - NPMLIST=$(nvm use system > /dev/null && npm list -g --depth=0 2> /dev/null | command tail -n +2) + NPMLIST=$(nvm use system > /dev/null && npm list -g --depth=0 2> /dev/null | command sed 1,1d) else - NPMLIST=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 2> /dev/null | command tail -n +2) + NPMLIST=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 2> /dev/null | command sed 1,1d) fi local INSTALLS diff --git "a/test/fast/Running \"nvm use system\" should work as expected" "b/test/fast/Running \"nvm use system\" should work as expected" index 4eb3319..28e5977 100755 --- "a/test/fast/Running \"nvm use system\" should work as expected" +++ "b/test/fast/Running \"nvm use system\" should work as expected" @@ -7,16 +7,16 @@ die () { echo $@ ; exit 1; } nvm_has_system_node() { return 0; } nvm_print_npm_version() { return ' (npm v1.2.3)'; } EXPECTED_OUTPUT="Now using system version of node: $(node -v)$(nvm_print_npm_version)" -[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Could not use system version of node" +[ "$(nvm use system 2>&1 | tail -1)" = "${EXPECTED_OUTPUT}" ] || die "Could not use system version of node" EXPECTED_OUTPUT="" -[ "$(nvm use --silent system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Could not use system version of node or --silent was not silent" +[ "$(nvm use --silent system 2>&1 | tail -1)" = "${EXPECTED_OUTPUT}" ] || die "Could not use system version of node or --silent was not silent" nvm_has_system_node() { return 1; } nvm_print_npm_version() { return ''; } EXPECTED_OUTPUT="System version of node not found." -[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Did not report error, system node not found" +[ "$(nvm use system 2>&1 | tail -1)" = "${EXPECTED_OUTPUT}" ] || die "Did not report error, system node not found" nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found" EXPECTED_OUTPUT="" -[ "$(nvm use --silent system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Did not report error, system node not found or --silent was not silent" +[ "$(nvm use --silent system 2>&1 | tail -1)" = "${EXPECTED_OUTPUT}" ] || die "Did not report error, system node not found or --silent was not silent" nvm use --silent system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found or --silent was not silent" diff --git a/test/installation_iojs/nvm install v1 works b/test/installation_iojs/nvm install v1 works index 67d6156..95ecc42 100755 --- a/test/installation_iojs/nvm install v1 works +++ b/test/installation_iojs/nvm install v1 works @@ -5,7 +5,7 @@ die () { echo $@ ; exit 1; } . ../../nvm.sh NVM_VERSION="v1" -NVM_PREFIXED_TEST_VERSION="$(nvm ls-remote "$NVM_VERSION" | tail -n1 | sed 's/^[ ]*//;s/[ ]*$//')" +NVM_PREFIXED_TEST_VERSION="$(nvm ls-remote "$NVM_VERSION" | tail -1 | sed 's/^[ ]*//;s/[ ]*$//')" NVM_TEST_VERSION="$(nvm_strip_iojs_prefix "$NVM_PREFIXED_TEST_VERSION")" # Remove the stuff we're clobbering.