ci, t, tools: use `command` and `type` instead of `which`
authorVille Skyttä <ville.skytta@upcloud.com>
Thu, 4 Nov 2021 07:30:28 +0000 (09:30 +0200)
committerVille Skyttä <ville.skytta@upcloud.com>
Sun, 20 Feb 2022 18:47:26 +0000 (20:47 +0200)
`which` is not POSIX, and cannot be assumed to installed everywhere.

`command -v` is available in POSIX and its predecessors at least since
1994: https://pubs.opengroup.org/onlinepubs/7908799/
It can be used as a replacement for `which` in a number of occurrences
in fio.

For bash scripts, `type -P` is available as a builtin replacement for
`which` and its $PATH search semantics.

Signed-off-by: Ville Skyttä <ville.skytta@upcloud.com>
ci/travis-install-pmdk.sh
t/one-core-peak.sh
tools/fio_generate_plots

index 803438f8f832a8b0ea1135a57e3ae3b977b0292d..3b0b5bbc56ac1a4960637874c223cf61796bcb97 100755 (executable)
@@ -12,7 +12,7 @@ WORKDIR=$(pwd)
 #    /bin/sh: 1: clang: not found
 # if CC is not set to the full path of clang.
 #
-export CC=$(which $CC)
+export CC=$(type -P $CC)
 
 # Install PMDK libraries, because PMDK's libpmem
 # is a dependency of the librpma fio engine.
index 9da8304e7dec8d2848a895e0453131b8c7074fe7..466dbdd45b3612ee7379debdd15cb4680face9db 100755 (executable)
@@ -33,7 +33,7 @@ check_binary() {
   # Ensure the binaries are present and executable
   for bin in "$@"; do
     if [ ! -x ${bin} ]; then
-      which ${bin} >/dev/null
+      command -v ${bin} >/dev/null
       [ $? -eq 0 ] || fatal "${bin} doesn't exists or is not executable"
     fi
   done
@@ -197,7 +197,7 @@ show_nvme() {
   fw=$(cat ${device_dir}/firmware_rev | xargs) #xargs for trimming spaces
   serial=$(cat ${device_dir}/serial | xargs) #xargs for trimming spaces
   info ${device_name} "MODEL=${model} FW=${fw} serial=${serial} PCI=${pci_addr}@${link_speed} IRQ=${irq} NUMA=${numa} CPUS=${cpus} "
-  which nvme &> /dev/null
+  command -v nvme > /dev/null
   if [ $? -eq 0 ]; then
     status=""
     NCQA=$(nvme get-feature -H -f 0x7 ${device} 2>&1 |grep NCQA |cut -d ':' -f 2 | xargs)
index e4558788150d2cadfa9706a24a16cb75c5994246..468cf27a6c2ae6dd693972947fd24d00f8933424 100755 (executable)
@@ -21,7 +21,7 @@ if [ -z "$1" ]; then
        exit 1
 fi
 
-GNUPLOT=$(which gnuplot)
+GNUPLOT=$(command -v gnuplot)
 if [ ! -x "$GNUPLOT" ]
 then
        echo You need gnuplot installed to generate graphs