Quantcast
Channel: User Kamil Maciorowski - Super User
Viewing all articles
Browse latest Browse all 645

Answer by Kamil Maciorowski for How to check if busybox has a command?

$
0
0
busybox --list | busybox grep -qF md5sum && echo yes || echo no

(Tested with Busybox v1.35.0 in Debian 12.)

A shell function that implements the above solution:

_busybox_has () { busybox --list | busybox grep -qxF "$1"; }

Usage:

_busybox_has md5sum && echo yes || echo no_busybox_has kitchensink && echo yes || echo no

there is no guarantee as to whether grep will be available

grep is so useful, it would be a peculiarity not to have it. Just in case, the following shell function implements _busybox_has using just busybox --list and features of the POSIX sh (not even [):

_busybox_has () {busybox --list | ( while IFS= read -r line; do   case "$line" in"$1") return 0         ;;   esacdonereturn 1 )}

Viewing all articles
Browse latest Browse all 645

Trending Articles