]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
grub-mkconfig: Use portable "command -v" to detect installed programs
authorEli Schwartz <eschwartz@archlinux.org>
Thu, 17 Oct 2019 03:03:06 +0000 (23:03 -0400)
committerDaniel Kiper <daniel.kiper@oracle.com>
Mon, 28 Oct 2019 14:38:48 +0000 (15:38 +0100)
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: ash, bash, busybox,
dash, ksh, mksh and 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
speedup.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
util/grub-mkconfig_lib.in
util/grub.d/30_os-prober.in

index 3e12b2c0e6adc92ea842eae85477ea79292db040..2d80f14bfcdab2f121e564615c04058006fbe8d2 100644 (file)
@@ -34,7 +34,7 @@ if test "x$grub_mkrelpath" = x; then
   grub_mkrelpath="${bindir}/@grub_mkrelpath@"
 fi
 
-if which gettext >/dev/null 2>/dev/null; then
+if command -v gettext >/dev/null; then
   :
 else
   gettext () {
index cf42f55e8b499695dc0c5674850dcdcdc2db8d70..1b91c102f35b3d1c131a4d267ea3cf8e98c88d56 100644 (file)
@@ -30,7 +30,7 @@ if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then
   exit 0
 fi
 
-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
 fi