treewide: replace `which` with `command -v`
authorPaul Spooren <mail@aparcar.org>
Mon, 10 Aug 2020 01:33:37 +0000 (15:33 -1000)
committerAdrian Schmutzler <freifunk@adrianschmutzler.de>
Wed, 12 Aug 2020 09:08:05 +0000 (11:08 +0200)
Fix shellcheck SC2230
> which is non-standard. Use builtin 'command -v' instead.

Using `command -v` is POSIX compliant while `which` is not.  Also to
mention, `command -v` is a shell builtin whereas `which` is a separate
busybox applet.

Once applied to everything concerning OpenWrt we can disable the busybox
feature `which` and save 3.8kB.

Acked-by: Stijn Tintel <stijn@linux-ipv6.be>
Signed-off-by: Paul Spooren <mail@aparcar.org>
[also replace cases in zram-swap]
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
include/rootfs.mk
package/base-files/files/lib/upgrade/stage2
package/kernel/broadcom-wl/files/lib/wifi/broadcom.sh
package/system/zram-swap/files/zram.init
scripts/ipkg-build

index b6775c7e15fb00e935737fd0b801ca7bef6e2a0d..18ada3cd432c79cbeaaf72224258508b467eee9a 100644 (file)
@@ -69,7 +69,7 @@ define prepare_rootfs
        @( \
                cd $(1); \
                for script in ./usr/lib/opkg/info/*.postinst; do \
-                       IPKG_INSTROOT=$(1) $$(which bash) $$script; \
+                       IPKG_INSTROOT=$(1) $$(command -v bash) $$script; \
                        ret=$$?; \
                        if [ $$ret -ne 0 ]; then \
                                echo "postinst script $$script has failed with exit code $$ret" >&2; \
@@ -79,10 +79,10 @@ define prepare_rootfs
                for script in ./etc/init.d/*; do \
                        grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
                        if ! echo " $(3) " | grep -q " $$(basename $$script) "; then \
-                               IPKG_INSTROOT=$(1) $$(which bash) ./etc/rc.common $$script enable; \
+                               IPKG_INSTROOT=$(1) $$(command -v bash) ./etc/rc.common $$script enable; \
                                echo "Enabling" $$(basename $$script); \
                        else \
-                               IPKG_INSTROOT=$(1) $$(which bash) ./etc/rc.common $$script disable; \
+                               IPKG_INSTROOT=$(1) $$(command -v bash) ./etc/rc.common $$script disable; \
                                echo "Disabling" $$(basename $$script); \
                        fi; \
                done || true \
index dbb33e8958c8c80325c32bacccfee8427fb04f5a..a4fef42134c87e311b3142289d1e32dcfb6614ed 100755 (executable)
@@ -45,7 +45,7 @@ switch_to_ramfs() {
                snapshot snapshot_tool                                  \
                $RAMFS_COPY_BIN
        do
-               local file="$(which "$binary" 2>/dev/null)"
+               local file="$(command -v "$binary" 2>/dev/null)"
                [ -n "$file" ] && install_bin "$file"
        done
        install_file /etc/resolv.conf /lib/*.sh /lib/functions/*.sh /lib/upgrade/*.sh /lib/upgrade/do_stage2 /usr/share/libubox/jshn.sh $RAMFS_COPY_DATA
index 33447341b259ba0493b1efe120a02988ce6b3dba..352c365f27521771ed64aee0d5801ce411ebba4a 100644 (file)
@@ -223,7 +223,7 @@ enable_broadcom() {
        }
 
        local _c=0
-       local nas="$(which nas)"
+       local nas="$(command -v nas)"
        local if_pre_up if_up nas_cmd
        local vif vif_pre_up vif_post_up vif_do_up vif_txpower
        local bssmax=$(wlc ifname "$device" bssmax)
index a6126e578f1feee445a6b245f85c255aa0cf05f7..42c084855ab68bde04bfef7ff81ab31379be913a 100755 (executable)
@@ -35,17 +35,17 @@ zram_applicable()
                return 1
        }
 
-       which mkswap >/dev/null || {
+       command -v mkswap >/dev/null || {
                logger -s -t zram_applicable -p daemon.err "[ERROR] 'mkswap' not installed"
                return 1
        }
 
-       which swapon >/dev/null || {
+       command -v swapon >/dev/null || {
                logger -s -t zram_applicable -p daemon.err "[ERROR] 'swapon' not installed"
                return 1
        }
 
-       which swapoff >/dev/null || {
+       command -v swapoff >/dev/null || {
                logger -s -t zram_applicable -p daemon.err "[ERROR] 'swapoff' not installed"
                return 1
        }
index 21127f33910cabb82f6b025a1865f305c88b9c10..6e027bc546338e63c61996be2b7ed898f4b6ad65 100755 (executable)
 set -e
 
 version=1.0
-FIND="$(which find)"
-FIND="${FIND:-$(which gfind)}"
-TAR="${TAR:-$(which tar)}"
-GZIP="$(which gzip)"
+FIND="$(command -v find)"
+FIND="${FIND:-$(command -v gfind)}"
+TAR="${TAR:-$(command -v tar)}"
+GZIP="$(command -v gzip)"
 
 # try to use fixed source epoch
 if [ -n "$SOURCE_DATE_EPOCH" ]; then
@@ -21,10 +21,10 @@ if [ -n "$SOURCE_DATE_EPOCH" ]; then
 
 # look up date of last commit
 elif [ -d "$TOPDIR/.git" ]; then
-       GIT="$(which git)"
+       GIT="$(command -v git)"
        TIMESTAMP=$(cd $TOPDIR; $GIT log -1 -s --format=%ci)
 elif [ -d "$TOPDIR/.svn" ]; then
-       SVN="$(which svn)"
+       SVN="$(command -v svn)"
        TIMESTAMP=$($SVN info "$TOPDIR" | sed -n "s/^Last Changed Date: \(.*\)/\1/p")
 else
        TIMESTAMP=$(date)