`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
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"
# 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
PATH=${PATH}:/usr/sbin
if test -z ${IP};then
- IP=$(which ip)
+ IP=$(command -v ip)
fi
if test "$(id -u)" != "0";then
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"
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=""
# - 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()
{
# 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