[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] grub-mkconfig: use portable 'command -v' to detect installed pro

From: Eli Schwartz
Subject: [PATCH] grub-mkconfig: use portable 'command -v' to detect installed programs
Date: Wed, 16 Oct 2019 23:03:06 -0400

The 'which' utility is not guaranteed to be installed either, and if it
is, its behavior is not portable either.

Conversely, the 'command -v' shell builtin is required to exist in all
POSIX 2008 compliant shells, and is thus guaranteed to work everywhere.

Examples of open-source shells likely to be installed as /bin/sh on
linux, which implement the 11-year-old standard:
bash, dash, busybox ash, ksh, mksh, zsh

A side benefit of using the POSIX portable option is that it requires
neither an external disk executable, nor (because unlike 'which', the
exit code is reliable) a subshell fork. This therefore represents a mild
 util/   | 2 +-
 util/grub.d/ | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/util/ b/util/
index 0f801cab3..50f2908d2 100644
--- a/util/
+++ b/util/
@@ -34,7 +34,7 @@ if test "x$grub_mkrelpath" = x; then
-if which gettext >/dev/null 2>/dev/null; then
+if command -v gettext >/dev/null; then
   gettext () {
diff --git a/util/grub.d/ b/util/grub.d/
index 515a68c7a..ed3171417 100644
--- a/util/grub.d/
+++ b/util/grub.d/
@@ -30,7 +30,7 @@ if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then
   exit 0
-if [ -z "`which os-prober 2> /dev/null`" ] || [ -z "`which linux-boot-prober 
2> /dev/null`" ] ; then
+if ! command -v os-prober > /dev/null || ! command -v linux-boot-prober > 
/dev/null ; then
   # missing os-prober and/or linux-boot-prober
   exit 0

reply via email to

[Prev in Thread] Current Thread [Next in Thread]