bin: Use command to check for commands

`command` is more idiomatic than `hash`. (Also, `hash` has side
effects.)
This commit is contained in:
Richard Hansen 2020-05-17 11:17:45 -04:00
parent 8e8b75be6c
commit a87a9bb63b
2 changed files with 9 additions and 5 deletions

View file

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
is_cmd() { command -v "$@" >/dev/null 2>&1; }
# Move to the folder where ep-lite is installed # Move to the folder where ep-lite is installed
cd $(dirname $0) cd $(dirname $0)
@ -9,19 +11,19 @@ if [ -d "../bin" ]; then
fi fi
# Is wget installed? # Is wget installed?
hash wget > /dev/null 2>&1 || { is_cmd wget || {
echo "Please install wget" >&2 echo "Please install wget" >&2
exit 1 exit 1
} }
# Is zip installed? # Is zip installed?
hash zip > /dev/null 2>&1 || { is_cmd zip || {
echo "Please install zip" >&2 echo "Please install zip" >&2
exit 1 exit 1
} }
# Is zip installed? # Is zip installed?
hash unzip > /dev/null 2>&1 || { is_cmd unzip || {
echo "Please install unzip" >&2 echo "Please install unzip" >&2
exit 1 exit 1
} }

View file

@ -8,6 +8,8 @@ REQUIRED_NODE_MINOR=13
REQUIRED_NPM_MAJOR=5 REQUIRED_NPM_MAJOR=5
REQUIRED_NPM_MINOR=5 REQUIRED_NPM_MINOR=5
is_cmd() { command -v "$@" >/dev/null 2>&1; }
require_minimal_version() { require_minimal_version() {
PROGRAM_LABEL="$1" PROGRAM_LABEL="$1"
VERSION_STRING="$2" VERSION_STRING="$2"
@ -58,13 +60,13 @@ fi
# Is node installed? # Is node installed?
# Not checking io.js, default installation creates a symbolic link to node # Not checking io.js, default installation creates a symbolic link to node
hash node > /dev/null 2>&1 || { is_cmd node || {
echo "Please install node.js ( https://nodejs.org )" >&2 echo "Please install node.js ( https://nodejs.org )" >&2
exit 1 exit 1
} }
# Is npm installed? # Is npm installed?
hash npm > /dev/null 2>&1 || { is_cmd npm || {
echo "Please install npm ( https://npmjs.org )" >&2 echo "Please install npm ( https://npmjs.org )" >&2
exit 1 exit 1
} }