diff options
| author | Eli Schwartz <eschwartz93@gmail.com> | 2023-11-26 12:01:51 -0500 |
|---|---|---|
| committer | Kernel Firmware Robot <linux-firmware@kernel.org> | 2023-11-26 11:09:32 -0600 |
| commit | c6823ce2e54879bf26c42ee7f1bb94fc571fddef (patch) | |
| tree | 0f672b3cde3df8abc9268ab21397da7e47510a18 /Makefile | |
| parent | f6d61dedddd593ef0e0619e6313c95034ba5a2f8 (diff) | |
Makefile, copy-firmware: Use portable "command -v" to detect installed programs
The "which" utility is not guaranteed to be installed either, and if it
is, its behavior is not portable either. This means that when rdfind /
pre-commit 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.
Conversely, the "command -v" shell builtin 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.
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 <eschwartz93@gmail.com>
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -6,7 +6,7 @@ FIRMWAREDIR = /lib/firmware all: check: - @if ! which pre-commit >/dev/null; then \ + @if ! command -v pre-commit >/dev/null; then \ echo "Install pre-commit to check files"; \ exit 1; \ fi |
