]> www.infradead.org Git - users/dwmw2/vpnc-scripts.git/commitdiff
Use `command -v` instead of `which`
authorVille Skyttä <ville.skytta@iki.fi>
Fri, 12 Nov 2021 21:47:56 +0000 (23:47 +0200)
committerVille Skyttä <ville.skytta@iki.fi>
Fri, 12 Nov 2021 22:07:06 +0000 (00:07 +0200)
`which` is not standard and might not be installed, whereas `command -v`
is in POSIX and its predecessor specs at least since 1994,
specified to produce no output when the arg command is not found.
https://pubs.opengroup.org/onlinepubs/7908799/xcu/command.html

`which` is also deprecated in Debian's debianutils 5.0+ and emits a
warning when used. At the moment, 5.0+ is only in Debian unstable, and
there is no other package in it providing `which`.
https://salsa.debian.org/debian/debianutils/-/commit/3a8dd10b4502f7bae8fc6973c13ce23fc9da7efb

tests/common.sh
tests/ns.sh
vpnc-script
vpnc-script-ptrtd
vpnc-script-sshd

index 5fbe882c50d40d7016e150bccc9610b6f16e095b..28f0b4a1ea1cec07678cd100bcf798868acc8254 100644 (file)
 builddir=${builddir:-.}
 srcdir=${srcdir:-.}
 
-OPENCONNECT=${OPENCONNECT:-$(which openconnect)}
-OCCTL=${OCCTL:-$(which occtl)}
-OCSERV=${OCSERV:-$(which ocserv)}
-IP=${IP:-$(which ip)}
+OPENCONNECT=${OPENCONNECT:-$(command -v openconnect)}
+OCCTL=${OCCTL:-$(command -v occtl)}
+OCSERV=${OCSERV:-$(command -v ocserv)}
+IP=${IP:-$(command -v ip)}
 
 if test -z "${OPENCONNECT}" || ! test -x ${OPENCONNECT};then
        echo "You need openconnect to run this test"
@@ -81,14 +81,14 @@ update_config() {
 # command in the caller's PFCMD, or exit, indicating an unsupported
 # test.  Prefer ss from iproute2 over the older netstat.
 have_port_finder() {
-       for file in $(which ss 2> /dev/null) /*bin/ss /usr/*bin/ss /usr/local/*bin/ss;do
+       for file in $(command -v ss) /*bin/ss /usr/*bin/ss /usr/local/*bin/ss;do
                if test -x "$file";then
                        PFCMD="$file";return 0
                fi
        done
 
        if test -z "$PFCMD";then
-       for file in $(which netstat 2> /dev/null) /bin/netstat /usr/bin/netstat /usr/local/bin/netstat;do
+       for file in $(command -v netstat) /bin/netstat /usr/bin/netstat /usr/local/bin/netstat;do
                if test -x "$file";then
                        PFCMD="$file";return 0
                fi
index 4d112abaa12bea8c592b76a764cc2cee9f44a1ba..2b65f81abca7e0317d2e7213ad1875bdbe249418 100644 (file)
@@ -37,7 +37,7 @@
 
 PATH=${PATH}:/usr/sbin
 if test -z ${IP};then
-       IP=$(which ip)
+       IP=$(command -v ip)
 fi
 
 if test "$(id -u)" != "0";then
index f75cc34cf54e4e8f965694efa2534e60508fd84a..113b6284bccc6fe93644e1167d67860252fb8c3c 100755 (executable)
@@ -120,7 +120,7 @@ else
 fi
 
 if [ "$OS" = "Linux" ]; then
-       IPROUTE="`which ip 2> /dev/null | grep '^/'`"
+       IPROUTE="`command -v ip | grep '^/'`"
        ifconfig_syntax_ptp="pointopoint"
        route_syntax_gw="gw"
        route_syntax_del="del"
@@ -132,7 +132,7 @@ if [ "$OS" = "Linux" ]; then
        ifconfig_syntax_del() { case "$1" in *:*) echo del "$1" ;; *) echo 0.0.0.0 ;; esac; }
        netstat_syntax_ipv6="-6"
 else
-       # iproute2 is Linux only; if `which ip` returns something on another OS, it's likely an unrelated tool
+       # iproute2 is Linux only; if `command -v ip` returns something on another OS, it's likely an unrelated tool
        # (see https://github.com/dlenski/openconnect/issues/132#issuecomment-470475009)
        IPROUTE=""
        ifconfig_syntax_ptp=""
index b97143b2d2567af28079ac5a3d4b53eee207deb5..d0a547b6a16a36df739ec085b60cd1f98f5ef65f 100755 (executable)
@@ -39,7 +39,7 @@
 #  - AAAA queries return the A result, converted to the above IPv6 space.
 #  - PTR queries within the IPv6 space converted appropriately.
 
-IP="`which ip 2> /dev/null | grep '^/'`"
+IP="`command -v ip | grep '^/'`"
 
 connect_parent()
 {
index 40e920566774421977eab5227354a078943176a9..d36ae194688cafb7864ea8ab44108e042987bea8 100755 (executable)
 # David Woodhouse <dwmw2@infradead.org>
 # 2009-06-06
 
-IP="`which ip 2> /dev/null | grep '^/'`"
+IP="`command -v ip | grep '^/'`"
 SCRIPTNAME=`basename $0`
 NETNSNAME=$SCRIPTNAME