Thanks for the push, Micah. It got my creative juices flowing.
Updated:
Tested on Bash 3/4, all builtins, no depedencies:
Portability: 100% compatible with Bash 3 and Bash 4 only
function _busybox_has() {
builtin command -v busybox >/dev/null ||
return 1
# Sanitize searches for '[' and '[['
a=$1
a=${a//[/\\[}
[[ $(busybox) =~ [[:space:]]($a)([,]|$) ]] ||
return 1
}
No bashisms, tested on Dash:
Portability: Portable on all sh with sed/egrep
_busybox_has() {
busybox 2>/dev/null >/dev/null ||
return 1
# Sanitize searches for '[' and '[['
a=$(echo $1 | sed 's/[[]/\\[/g')
busybox | egrep -oq "[[:space:]]($a)([,]|$)" ||
return 1
}
No bashisms, grep -e instead of egrep (more portable), tested on Dash:
Portability: Portable on all sh with sed/grep -e
_busybox_has() {
busybox 2>/dev/null >/dev/null ||
return 1
# Sanitize searches for '[' and '[['
a=$(echo $1 | sed 's/[[]/\\[/g')
busybox | grep -oqe "[[:space:]]\($a\)\([,]\|\$\)" ||
return 1
}
To test:
_busybox_has md5sum && echo yes || echo no