@@ -349,7 +349,7 @@ char *ping_command(int family)
{
if (family == AF_INET6) {
/* On some systems 'ping' doesn't support IPv6, so use ping6 if it is present. */
- if (!system("which ping6 >/dev/null 2>&1"))
+ if (!system("command -v ping6 >/dev/null 2>&1"))
return "ping6";
else
return "ping -6";
@@ -19,7 +19,7 @@ fi
# namespace.
if [[ -z $(ip netns identify $$) ]]; then
err=0
- if bpftool="$(which bpftool)"; then
+ if bpftool="$(command -v bpftool)"; then
echo "Testing global flow dissector..."
$bpftool prog loadall ./bpf_flow.o /sys/fs/bpf/flow \
@@ -61,7 +61,7 @@ check_env()
exit 4
fi
- which tcpdump &>/dev/null
+ command -v tcpdump &>/dev/null
if [ $? -ne 0 ];then
echo "selftests: [SKIP] Could not run test without tcpdump"
exit 4
@@ -134,9 +134,9 @@ fi
set -e
# Some shell-tools dependencies
-which ip > /dev/null
-which tc > /dev/null
-which ethtool > /dev/null
+command -v ip > /dev/null
+command -v tc > /dev/null
+command -v ethtool > /dev/null
# Make rest of shell verbose, showing comments as doc/info
if [ -n "$VERBOSE" ]; then
@@ -97,7 +97,7 @@ download_rootfs()
local rootfsversion="$1"
local dir="$2"
- if ! which zstd &> /dev/null; then
+ if ! command -v zstd &> /dev/null; then
echo 'Could not find "zstd" on the system, please install zstd'
exit 1
fi
@@ -212,7 +212,7 @@ run_vm()
local kernel_bzimage="$1"
local rootfs_img="${OUTPUT_DIR}/${ROOTFS_IMAGE}"
- if ! which "${QEMU_BINARY}" &> /dev/null; then
+ if ! command -v "${QEMU_BINARY}" &> /dev/null; then
cat <<EOF
Could not find ${QEMU_BINARY}
Please install qemu or set the QEMU_BINARY environment variable.
@@ -99,7 +99,7 @@ check_setup()
OLD_FWPATH="$(cat /sys/module/firmware_class/parameters/path)"
if [ "$HAS_FW_LOADER_COMPRESS" = "yes" ]; then
- if ! which xz 2> /dev/null > /dev/null; then
+ if ! command -v xz 2> /dev/null > /dev/null; then
HAS_FW_LOADER_COMPRESS=""
fi
fi
@@ -9,7 +9,7 @@ if [ $uid -ne 0 ]; then
exit 1
fi
-if ! which modprobe > /dev/null 2>&1; then
+if ! command -v modprobe > /dev/null 2>&1; then
echo "$0: You need modprobe installed"
exit 4
fi
@@ -7,7 +7,7 @@ if [ ! -f $FTRACETEST_ROOT/ftracetest ]; then
exit_unresolved
fi
-if ! which checkbashisms > /dev/null 2>&1 ; then
+if ! command -v checkbashisms > /dev/null 2>&1 ; then
echo "No checkbashisms found. skipped."
exit_unresolved
fi
@@ -3,7 +3,7 @@
# description: Test wakeup tracer
# requires: wakeup:tracer
-if ! which chrt ; then
+if ! command -v chrt ; then
echo "chrt is not found. This test requires nice command."
exit_unresolved
fi
@@ -3,7 +3,7 @@
# description: Test wakeup RT tracer
# requires: wakeup_rt:tracer
-if ! which chrt ; then
+if ! command -v chrt ; then
echo "chrt is not found. This test requires chrt command."
exit_unresolved
fi
@@ -59,7 +59,7 @@ is_ima_sig_required()
# Return 1 for PE signature found and 0 for not found.
check_for_pesig()
{
- which pesign > /dev/null 2>&1 || log_skip "pesign not found"
+ command -v pesign > /dev/null 2>&1 || log_skip "pesign not found"
pesign -i $KERNEL_IMAGE --show-signature | grep -q "No signatures"
local ret=$?
@@ -77,7 +77,7 @@ check_for_imasig()
{
local ret=0
- which getfattr > /dev/null 2>&1
+ command -v getfattr > /dev/null 2>&1
if [ $? -eq 1 ]; then
log_skip "getfattr not found"
fi
@@ -110,12 +110,12 @@ function allow_user_defaults()
test_reqs()
{
- if ! which modprobe 2> /dev/null > /dev/null; then
+ if ! command -v modprobe 2> /dev/null > /dev/null; then
echo "$0: You need modprobe installed" >&2
exit $ksft_skip
fi
- if ! which kmod 2> /dev/null > /dev/null; then
+ if ! command -v kmod 2> /dev/null > /dev/null; then
echo "$0: You need kmod installed" >&2
exit $ksft_skip
fi
@@ -82,7 +82,7 @@ NSA_CMD="ip netns exec ${NSA}"
NSB_CMD="ip netns exec ${NSB}"
NSC_CMD="ip netns exec ${NSC}"
-which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
+command -v ping6 > /dev/null 2>&1 && ping6=$(command -v ping6) || ping6=$(command -v ping)
################################################################################
# utilities
@@ -4037,7 +4037,7 @@ elif [ "$TESTS" = "ipv6" ]; then
TESTS="$TESTS_IPV6"
fi
-which nettest >/dev/null
+command -v nettest >/dev/null
if [ $? -ne 0 ]; then
echo "'nettest' command not found; skipping tests"
exit $ksft_skip
@@ -15,7 +15,7 @@
PAUSE_ON_FAIL=no
VERBOSE=0
-which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
+command -v ping6 > /dev/null 2>&1 && ping6=$(command -v ping6) || ping6=$(command -v ping)
################################################################################
# helpers
@@ -17,7 +17,7 @@ PAUSE=no
IP="ip -netns ns1"
NS_EXEC="ip netns exec ns1"
-which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
+command -v ping6 > /dev/null 2>&1 && ping6=$(command -v ping6) || ping6=$(command -v ping)
log_test()
{
@@ -488,7 +488,7 @@ EOF
# main
# Some systems don't have a ping6 binary anymore
-which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
+command -v ping6 > /dev/null 2>&1 && ping6=$(command -v ping6) || ping6=$(command -v ping)
ret=0
nsuccess=0
@@ -16,7 +16,7 @@
VERBOSE=0
PAUSE_ON_FAIL=no
-which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
+command -v ping6 > /dev/null 2>&1 && ping6=$(command -v ping6) || ping6=$(command -v ping)
################################################################################
#
@@ -197,7 +197,7 @@ VERBOSE=0
TRACING=0
# Some systems don't have a ping6 binary anymore
-which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
+command -v ping6 > /dev/null 2>&1 && ping6=$(command -v ping6) || ping6=$(command -v ping)
# Name Description re-run with nh
tests="
@@ -661,7 +661,7 @@ setup_xfrm() {
}
setup_nettest_xfrm() {
- which nettest >/dev/null
+ command -v nettest >/dev/null
if [ $? -ne 0 ]; then
echo "'nettest' command not found; skipping tests"
return 1
@@ -1777,7 +1777,7 @@ test_pmtu_vti6_link_change_mtu() {
check_command() {
cmd=${1}
- if ! which ${cmd} > /dev/null 2>&1; then
+ if ! command -v ${cmd} > /dev/null 2>&1; then
err " missing required command: '${cmd}'"
return 1
fi
@@ -2072,7 +2072,7 @@ do
case $o in
p) PAUSE_ON_FAIL=yes;;
v) VERBOSE=1;;
- t) if which tcpdump > /dev/null 2>&1; then
+ t) if command -v tcpdump > /dev/null 2>&1; then
TRACING=1
else
echo "=== tcpdump not available, tracing disabled"
@@ -32,9 +32,9 @@
ksft_skip=4
# nettest can be run from PATH or from same directory as this selftest
-if ! which nettest >/dev/null; then
+if ! command -v nettest >/dev/null; then
PATH=$PWD:$PATH
- if ! which nettest >/dev/null; then
+ if ! command -v nettest >/dev/null; then
echo "'nettest' command not found; skipping tests"
exit $ksft_skip
fi
@@ -31,7 +31,7 @@ ENC_2=0x3fb07ac2a91f0347dffeacf62fc46c20f8048be9725930ff
SPI_1=0x02122b77
SPI_2=0x2b770212
-which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
+command -v ping6 > /dev/null 2>&1 && ping6=$(command -v ping6) || ping6=$(command -v ping)
################################################################################
#
@@ -41,7 +41,7 @@ checktool (){
checktool "iptables --version" "run test without iptables"
checktool "ip -Version" "run test without ip tool"
-checktool "which nc" "run test without nc (netcat)"
+checktool "command -v nc" "run test without nc (netcat)"
checktool "ip netns add ${r_a}" "create net namespace"
for n in ${r_b} ${r_w} ${c_a} ${c_b};do
@@ -37,7 +37,7 @@ if [ $? -ne 0 ];then
exit $ksft_skip
fi
-which nc >/dev/null 2>&1
+command -v nc >/dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without netcat tool"
exit $ksft_skip
@@ -35,7 +35,7 @@ checktool (){
checktool "nft --version" "run test without nft tool"
checktool "ip -Version" "run test without ip tool"
-checktool "which nc" "run test without nc (netcat)"
+checktool "command -v nc" "run test without nc (netcat)"
checktool "ip netns add nsr1" "create net namespace"
ip netns add ns1
@@ -9,9 +9,9 @@
if [ -x ./getscom ] && [ -x ./putscom ]; then
GETSCOM=./getscom
PUTSCOM=./putscom
-elif which getscom > /dev/null; then
- GETSCOM=$(which getscom)
- PUTSCOM=$(which putscom)
+elif command -v getscom > /dev/null; then
+ GETSCOM=$(command -v getscom)
+ PUTSCOM=$(command -v putscom)
else
cat <<EOF
Can't find getscom/putscom in . or \$PATH.
@@ -97,15 +97,15 @@ test_reqs()
exit $ksft_skip
fi
- if ! which perl 2> /dev/null > /dev/null; then
+ if ! command -v perl 2> /dev/null > /dev/null; then
echo "$0: You need perl installed"
exit $ksft_skip
fi
- if ! which getconf 2> /dev/null > /dev/null; then
+ if ! command -v getconf 2> /dev/null > /dev/null; then
echo "$0: You need getconf installed"
exit $ksft_skip
fi
- if ! which diff 2> /dev/null > /dev/null; then
+ if ! command -v diff 2> /dev/null > /dev/null; then
echo "$0: You need diff installed"
exit $ksft_skip
fi
@@ -26,7 +26,7 @@ check_test_requirements()
exit $ksft_skip
fi
- if ! which modprobe > /dev/null 2>&1; then
+ if ! command -v modprobe > /dev/null 2>&1; then
echo "$0: You need modprobe installed"
exit $ksft_skip
fi
@@ -35,7 +35,7 @@ check_test_requirements()
exit $ksft_skip
fi
- if ! which modprobe > /dev/null 2>&1; then
+ if ! command -v modprobe > /dev/null 2>&1; then
echo "$0: You need modprobe installed"
exit $ksft_skip
fi
@@ -199,7 +199,7 @@ zram_makefs()
local i=0
for fs in $zram_filesystems; do
# if requested fs not supported default it to ext2
- which mkfs.$fs > /dev/null 2>&1 || fs=ext2
+ command -v mkfs.$fs > /dev/null 2>&1 || fs=ext2
echo "make $fs filesystem on /dev/zram$i"
mkfs.$fs /dev/zram$i > err.log 2>&1
As /usr/share/doc/debianutils/NEWS.Debian.gz says: * The 'which' utility will be removed in the future. Shell scripts often use it to check whether a command is available. A more standard way to do this is with 'command -v'; for example: if command -v update-icon-caches >/dev/null; then update-icon-caches /usr/share/icons/... fi '2>/dev/null' is unnecessary when using 'command': POSIX says "no output shall be written" if the command isn't found. It's also unnecessary for the debianutils version of 'which', and hides the deprecation warning. Starting with debianutils 5.4 "which" is spitting out the following warning: this version of `which' is deprecated; use `command -v' in scripts instead Start to transition from "which" to "command -v" in the selftests scripts. Signed-off-by: Andrea Righi <andrea.righi@canonical.com> --- tools/testing/selftests/bpf/network_helpers.c | 2 +- tools/testing/selftests/bpf/test_flow_dissector.sh | 2 +- tools/testing/selftests/bpf/test_xdp_redirect_multi.sh | 2 +- tools/testing/selftests/bpf/test_xdp_vlan.sh | 6 +++--- tools/testing/selftests/bpf/vmtest.sh | 4 ++-- tools/testing/selftests/firmware/fw_lib.sh | 2 +- tools/testing/selftests/fpu/run_test_fpu.sh | 2 +- .../testing/selftests/ftrace/test.d/selftest/bashisms.tc | 2 +- tools/testing/selftests/ftrace/test.d/tracer/wakeup.tc | 2 +- tools/testing/selftests/ftrace/test.d/tracer/wakeup_rt.tc | 2 +- tools/testing/selftests/kexec/test_kexec_file_load.sh | 4 ++-- tools/testing/selftests/kmod/kmod.sh | 4 ++-- tools/testing/selftests/net/fcnal-test.sh | 4 ++-- tools/testing/selftests/net/fib_nexthop_multiprefix.sh | 2 +- tools/testing/selftests/net/fib_tests.sh | 2 +- tools/testing/selftests/net/icmp_redirect.sh | 2 +- tools/testing/selftests/net/l2tp.sh | 2 +- tools/testing/selftests/net/pmtu.sh | 8 ++++---- tools/testing/selftests/net/unicast_extensions.sh | 4 ++-- tools/testing/selftests/net/vrf-xfrm-tests.sh | 2 +- tools/testing/selftests/netfilter/ipip-conntrack-mtu.sh | 2 +- tools/testing/selftests/netfilter/nft_conntrack_helper.sh | 2 +- tools/testing/selftests/netfilter/nft_flowtable.sh | 2 +- tools/testing/selftests/powerpc/scripts/hmi.sh | 6 +++--- tools/testing/selftests/sysctl/sysctl.sh | 6 +++--- tools/testing/selftests/vm/test_hmm.sh | 2 +- tools/testing/selftests/vm/test_vmalloc.sh | 2 +- tools/testing/selftests/zram/zram_lib.sh | 2 +- 28 files changed, 42 insertions(+), 42 deletions(-)