Skip to contentSkip to conversation

install-dep: Use command -v instead of which

PATCH In review Petr Vorel 2 participants 3 messages Sep 20, 2021 – Sep 23, 2021

Subsystems (2)
lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 install-dep: Use command -v instead of which

command -v' is shell builtin required by POSIX [1] and supported on all common shells (bash, zsh, dash, busybox sh, mksh). which' utility is not presented on some containers (e.g. Fedora, openSUSE), also going to be removed from future Debian versions.

Also remove stderr redirection to /dev/null as it's unnecessary when using 'command': POSIX says "no output shall be written" if the command isn't found.

[1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html
[2] https://salsa.debian.org/debian/debianutils/-/commit/3a8dd10b4502f7bae8fc6973c13ce23fc9da7efb

---
 install-dep | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
install-dep +3 -3
index 621618fe..4698d44a 100755
@@ -2,20 +2,20 @@
 #install dependencies for compiling from source code
 
 #RHEL/Fedora/CentOS-Stream/Rocky
-which dnf &>/dev/null || which yum &>/dev/null && {
+command -v dnf >/dev/null || command -v yum >/dev/null && {
 	yum install -y automake libtool make gcc rpcgen libtirpc-devel libevent-devel sqlite-devel device-mapper-devel \
 		libblkid-devel krb5-devel libuuid-devel
 }
 
 #Debian/ubuntu
-which apt &>/dev/null && {
+command -v apt >/dev/null && {
 	apt install -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 --ignore-missing -y \
 		autotools-dev automake make libtool pkg-config libtirpc-dev libevent-dev libsqlite3-dev \
 		libdevmapper-dev libblkid-dev libkrb5-dev libkeyutils-dev uuid-dev
 }
 
 #openSUSE Leap
-which zypper &>/dev/null && {
+command -v zypper >/dev/null && {
 	zypper in --no-recommends -y automake libtool make gcc rpcgen libtirpc-devel libevent-devel sqlite-devel \
 		device-mapper-devel libblkid-devel krb5-devel libuuid-devel
 }
Signature · 1 line
2.33.0
author
#1 lore raw
Quoted 8 lines

command -v' is shell builtin required by POSIX [1] and supported on all common shells (bash, zsh, dash, busybox sh, mksh). which' utility is not presented on some containers (e.g. Fedora, openSUSE), also going to be removed from future Debian versions.

Also remove stderr redirection to /dev/null as it's unnecessary when using 'command': POSIX says "no output shall be written" if the command isn't found.

nit: [2] missing at the end of this paragraph.

Kind regards,
Petr

Quoted 36 lines

[1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html
[2] https://salsa.debian.org/debian/debianutils/-/commit/3a8dd10b4502f7bae8fc6973c13ce23fc9da7efb

---
 install-dep | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
install-dep +3 -3
index 621618fe..4698d44a 100755
@@ -2,20 +2,20 @@
 #install dependencies for compiling from source code
 
 #RHEL/Fedora/CentOS-Stream/Rocky
-which dnf &>/dev/null || which yum &>/dev/null && {
+command -v dnf >/dev/null || command -v yum >/dev/null && {
 	yum install -y automake libtool make gcc rpcgen libtirpc-devel libevent-devel sqlite-devel device-mapper-devel \
 		libblkid-devel krb5-devel libuuid-devel
 }
 
 #Debian/ubuntu
-which apt &>/dev/null && {
+command -v apt >/dev/null && {
 	apt install -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 --ignore-missing -y \
 		autotools-dev automake make libtool pkg-config libtirpc-dev libevent-dev libsqlite3-dev \
 		libdevmapper-dev libblkid-dev libkrb5-dev libkeyutils-dev uuid-dev
 }
 
 #openSUSE Leap
-which zypper &>/dev/null && {
+command -v zypper >/dev/null && {
 	zypper in --no-recommends -y automake libtool make gcc rpcgen libtirpc-devel libevent-devel sqlite-devel \
 		device-mapper-devel libblkid-devel krb5-devel libuuid-devel
 }
#2 lore raw
In reply to Petr Vorel
Quoted 5 lines · Petr Vorel

command -v' is shell builtin required by POSIX [1] and supported on all common shells (bash, zsh, dash, busybox sh, mksh). which' utility is not presented on some containers (e.g. Fedora, openSUSE), also going to be removed from future Debian versions.

Quoted 8 lines

Also remove stderr redirection to /dev/null as it's unnecessary when using 'command': POSIX says "no output shall be written" if the command isn't found.

[1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html
[2] https://salsa.debian.org/debian/debianutils/-/commit/3a8dd10b4502f7bae8fc6973c13ce23fc9da7efb

Committed... (tag: nfs-utils-2-5-5-rc3)

steved.

Quoted 33 lines
---
  install-dep | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
install-dep +3 -3
index 621618fe..4698d44a 100755
@@ -2,20 +2,20 @@
  #install dependencies for compiling from source code
 
  #RHEL/Fedora/CentOS-Stream/Rocky
-which dnf &>/dev/null || which yum &>/dev/null && {
+command -v dnf >/dev/null || command -v yum >/dev/null && {
  	yum install -y automake libtool make gcc rpcgen libtirpc-devel libevent-devel sqlite-devel device-mapper-devel \
  		libblkid-devel krb5-devel libuuid-devel
  }
 
  #Debian/ubuntu
-which apt &>/dev/null && {
+command -v apt >/dev/null && {
  	apt install -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 --ignore-missing -y \
  		autotools-dev automake make libtool pkg-config libtirpc-dev libevent-dev libsqlite3-dev \
  		libdevmapper-dev libblkid-dev libkrb5-dev libkeyutils-dev uuid-dev
  }
 
  #openSUSE Leap
-which zypper &>/dev/null && {
+command -v zypper >/dev/null && {
  	zypper in --no-recommends -y automake libtool make gcc rpcgen libtirpc-devel libevent-devel sqlite-devel \
  		device-mapper-devel libblkid-devel krb5-devel libuuid-devel
  }