Skip to content

`command -v` portability

Eli Schwartz requested to merge eschwartz/xdg-utils:command-v-portability into master

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

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 12-year-old standard: ash, bash, busybox, dash, ksh, mksh and zsh.

A side benefit of using the POSIX portable option is that it does not require an external disk executable to be forked. This therefore represents a mild speedup.

Merge request reports

Loading