I tried different variants
echo $0
echo $shell
echo $SHELL
ps -p $$
but none of them can give a distinctive output. I can do something like this but it's ugly and hackish:
if ls --help 2>&1 | grep BusyBox; then
echo "it is BusyBox"
else
echo "it is NOT BusyBox"
fi
Another way requiring Linux and readlink
:
#!/bin/ash
exe=`exec 2>/dev/null; readlink "/proc/$$/exe"`
case "$exe" in
*/busybox)
echo "It's a busybox shell."
;;
esac
Personally I favour:
if ps ax -o pid,comm | grep `echo $$` | grep busybox ; then
echo "it is BusyBox"
fi
Which is a fair check to ensure you are running busybox shell.
This works by having ps generate a list of pids vs program names then finding our pid and checking if the program name contains busybox.
Might not be perfect but this is how I check:
test -h /bin/ls # busybox or other single binary system
test -h /bin/ls && test `readlink /bin/ls` = busybox # it is busybox
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.