From 63dcc02cbb73e5b00da41f7adfb1f94fb56499df Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Mon, 13 May 2019 18:58:16 -0400 Subject: [PATCH] Fix use of which command The 'which' command is the wrong tool for the job for several reasons. The protable way to check if a tool is available in a shell is 'command -v'. Also see https://stackoverflow.com/q/592620/608639 --- Makefile.in | 4 ++-- test/common.sh | 16 ++++++++-------- test/test_all.sh | 2 +- test/test_ci.sh | 2 +- test/testbed/do-tests.sh | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Makefile.in b/Makefile.in index f7b0a8ab..752001ac 100644 --- a/Makefile.in +++ b/Makefile.in @@ -291,7 +291,7 @@ manpage-errors: echo doc/man/man3/$${m}.3: manpage-has-bad-whatis-entry; \ fi; \ done || echo "WARNING!: Cannot detect manpage errors on `uname`" - + pyldns: _ldns.la $(pywrapdir)/ldns_wrapper.c: $(PYLDNS_I_FILES) ldns/config.h @@ -483,7 +483,7 @@ test-clean: tpkg -b test clean test: @TEST_P5_DNS_LDNS@ - if test -x "`which bash`"; then bash test/test_all.sh; else sh test/test_all.sh; fi + if test -x "`command -v bash`"; then bash test/test_all.sh; else sh test/test_all.sh; fi # Recreate symbols file, only needed when API changes diff --git a/test/common.sh b/test/common.sh index 8e3b2293..c57defa3 100644 --- a/test/common.sh +++ b/test/common.sh @@ -47,7 +47,7 @@ info () { # test if 'tool' is available in path and complain otherwise. # $1: tool test_tool_avail () { - if test ! -x "`which $1 2>&1`"; then + if test ! -x "`command -v $1 2>&1`"; then echo No "$1" in path exit 1 fi @@ -55,7 +55,7 @@ test_tool_avail () { # get ldns-testns tool in LDNS_TESTNS variable. get_ldns_testns () { - if test -x "`which ldns-testns 2>&1`"; then + if test -x "`command -v ldns-testns 2>&1`"; then LDNS_TESTNS=ldns-testns else LDNS_TESTNS=/home/wouter/bin/ldns-testns @@ -64,7 +64,7 @@ get_ldns_testns () { # get make tool in MAKE variable, gmake is used if present. get_make () { - if test -x "`which gmake 2>&1`"; then + if test -x "`command -v gmake 2>&1`"; then MAKE=gmake else MAKE=make @@ -73,7 +73,7 @@ get_make () { # get cc tool in CC variable, gcc is used if present. get_gcc () { - if test -x "`which gcc 2>&1`"; then + if test -x "`command -v gcc 2>&1`"; then CC=gcc else CC=cc @@ -82,9 +82,9 @@ get_gcc () { # get pcat, pcat-print and pcat-diff get_pcat () { - PCAT=`which pcat` - PCAT_PRINT=`which pcat-print` - PCAT_DIFF=`which pcat-diff` + PCAT=`command -v pcat` + PCAT_PRINT=`command -v pcat-print` + PCAT_DIFF=`command -v pcat-diff` } # set SKIP=1 if the name is in list and tool is not available. @@ -93,7 +93,7 @@ get_pcat () { # #3: name of the tool required. skip_if_in_list () { if echo $2 | grep $1 >/dev/null; then - if test ! -x "`which $3 2>&1`"; then + if test ! -x "`command -v $3 2>&1`"; then SKIP=1; fi fi diff --git a/test/test_all.sh b/test/test_all.sh index cdc4eca8..767f31fe 100755 --- a/test/test_all.sh +++ b/test/test_all.sh @@ -4,7 +4,7 @@ cd test . common.sh # find tpkg -if test -x "`which tpkg 2>&1`"; then +if test -x "`command -v tpkg 2>&1`"; then TPKG=tpkg else TPKG=$1 diff --git a/test/test_ci.sh b/test/test_ci.sh index 14fd6c1d..84e9a294 100755 --- a/test/test_ci.sh +++ b/test/test_ci.sh @@ -19,7 +19,7 @@ fi if [ -z "$TPKG" -o ! -x "$TPKG" ] then - if which tpkg > /dev/null ; then TPKG=`which tpkg` + if which tpkg > /dev/null ; then TPKG=`command -v tpkg` elif [ -x $HOME/bin/tpkg ] ; then TPKG=$HOME/bin/tpkg elif [ -x $HOME/local/bin/tpkg ]; then TPKG=$HOME/local/bin/tpkg elif [ -x /home/tpkg/bin/tpkg ] ; then TPKG=/home/tpkg/bin/tpkg diff --git a/test/testbed/do-tests.sh b/test/testbed/do-tests.sh index a8580746..0e394e8c 100755 --- a/test/testbed/do-tests.sh +++ b/test/testbed/do-tests.sh @@ -8,12 +8,12 @@ cd testdata; for test in `ls *.tpkg`; do SKIP=0 if echo $NEED_SPLINT | grep $test >/dev/null; then - if test ! -x "`which splint`"; then + if test ! -x "`command -v splint`"; then SKIP=1; fi fi if echo $NEED_DOXYGEN | grep $test >/dev/null; then - if test ! -x "`which doxygen`"; then + if test ! -x "`command -v doxygen`"; then SKIP=1; fi fi -- 2.47.3