From 293c6d198b3e9fc16be478cce9243328f2e1377a Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Fri, 18 Nov 2016 03:51:28 +0800 Subject: [PATCH] Use `which` instead of `type` to detect if command exists `type` will not confirm the file in $PATH is executable or not. --- install.sh | 2 +- nvm.sh | 2 +- test/fast/Unit tests/nvm_has | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index bff211c..6fe4b4f 100755 --- a/install.sh +++ b/install.sh @@ -3,7 +3,7 @@ { # this ensures the entire script is downloaded # nvm_has() { - type "$1" > /dev/null 2>&1 + command which "${1-}" > /dev/null 2>&1 } nvm_install_dir() { diff --git a/nvm.sh b/nvm.sh index 544245d..a056703 100755 --- a/nvm.sh +++ b/nvm.sh @@ -36,7 +36,7 @@ nvm_grep() { } nvm_has() { - type "${1-}" > /dev/null 2>&1 + command which "${1-}" > /dev/null 2>&1 } nvm_is_alias() { diff --git a/test/fast/Unit tests/nvm_has b/test/fast/Unit tests/nvm_has index c1a3b59..dc0260c 100755 --- a/test/fast/Unit tests/nvm_has +++ b/test/fast/Unit tests/nvm_has @@ -4,9 +4,9 @@ die () { echo "$@" ; exit 1; } \. ../../../nvm.sh -nvm_has cat && type cat > /dev/null || die 'nvm_has locates "cat" properly' +nvm_has cat && command which cat > /dev/null || die 'nvm_has locates "cat" properly' [ "~$(nvm_has foobarbaz 2>&1)" = "~" ] || die "nvm_has does not suppress error output" -! nvm_has foobarbaz && ! type foobarbaz >/dev/null 2>&1 || die "nvm_has does not return a nonzero exit code when not found" +! nvm_has foobarbaz && ! command which foobarbaz >/dev/null 2>&1 || die "nvm_has does not return a nonzero exit code when not found"