Skip to content

use portable "command -v" to detect installed programs

Eli Schwartz requested to merge eschwartz/pyatspi2:which-hunt into master

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:

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.

Several Linux distros which do currently ship a (decent quality) which utility in their default install are looking to get rid of it:

Merge request reports