use portable "command -v" to detect installed programs, part 5

The "which" utility is not guaranteed to be installed either, and if it
is, its behavior is not portable either. This means that when various
programs are installed, the `which` check will report a fatal error
because the which tool did not exist and the shell returned a nonzero
status when attempting to fork+exec. If it did exist, it might not be an
implementation of `which` that returns nonzero when commands do not
exist.

The general scripting suggestion is to use the "command -v" shell
builtin; this is required to exist in all POSIX 2008 compliant shells,
and is thus guaranteed to work everywhere.

For some in-depth discussions on the topic, see:
- https://mywiki.wooledge.org/BashFAQ/081
- https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then/85250#85250

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

This commit updates documentation to no longer suggest a bad practice
that will confuse the reader when it doesn't work.

Change-Id: I0ed5ced353124919c7e09912c6d4d5aea146fa33
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160666
Tested-by: Ilmari Lauhakangas <ilmari.lauhakangas@libreoffice.org>
Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakangas@libreoffice.org>
This commit is contained in:
Eli Schwartz 2023-12-13 00:01:39 -05:00 committed by Ilmari Lauhakangas
parent 2a5ff80264
commit ceb885232a
5 changed files with 9 additions and 9 deletions

View file

@ -1661,7 +1661,7 @@ EXTERNAL_GROUPS = YES
EXTERNAL_PAGES = YES
# The PERL_PATH should be the absolute path and name of the perl script
# interpreter (i.e. the result of `which perl').
# interpreter (i.e. the result of `command -v perl').
PERL_PATH = /usr/bin/perl

View file

@ -2085,7 +2085,7 @@ EXTERNAL_GROUPS = YES
EXTERNAL_PAGES = YES
# The PERL_PATH should be the absolute path and name of the perl script
# interpreter (i.e. the result of 'which perl').
# interpreter (i.e. the result of 'command -v perl').
# The default file (with absolute path) is: /usr/bin/perl.
PERL_PATH =
@ -2300,7 +2300,7 @@ DOT_IMAGE_FORMAT = svg
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.
INTERACTIVE_SVG = YES
INTERACTIVE_SVG = YES
# The DOT_PATH tag can be used to specify the path where the dot tool can be
# found. If left blank, it is assumed the dot tool can be found in the path.

View file

@ -2085,7 +2085,7 @@ EXTERNAL_GROUPS = YES
EXTERNAL_PAGES = YES
# The PERL_PATH should be the absolute path and name of the perl script
# interpreter (i.e. the result of 'which perl').
# interpreter (i.e. the result of 'command -v perl').
# The default file (with absolute path) is: /usr/bin/perl.
PERL_PATH =
@ -2300,7 +2300,7 @@ DOT_IMAGE_FORMAT = svg
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.
INTERACTIVE_SVG = YES
INTERACTIVE_SVG = YES
# The DOT_PATH tag can be used to specify the path where the dot tool can be
# found. If left blank, it is assumed the dot tool can be found in the path.
@ -2398,4 +2398,4 @@ GENERATE_LEGEND = YES
# The default value is: YES.
# This tag requires that the tag HAVE_DOT is set to YES.
DOT_CLEANUP = YES
DOT_CLEANUP = YES

View file

@ -2085,7 +2085,7 @@ EXTERNAL_GROUPS = YES
EXTERNAL_PAGES = YES
# The PERL_PATH should be the absolute path and name of the perl script
# interpreter (i.e. the result of 'which perl').
# interpreter (i.e. the result of 'command -v perl').
# The default file (with absolute path) is: /usr/bin/perl.
PERL_PATH =
@ -2300,7 +2300,7 @@ DOT_IMAGE_FORMAT = svg
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.
INTERACTIVE_SVG = YES
INTERACTIVE_SVG = YES
# The DOT_PATH tag can be used to specify the path where the dot tool can be
# found. If left blank, it is assumed the dot tool can be found in the path.

View file

@ -1078,7 +1078,7 @@ ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
# The PERL_PATH should be the absolute path and name of the perl script
# interpreter (i.e. the result of `which perl').
# interpreter (i.e. the result of `command -v perl').
PERL_PATH = /usr/bin/perl