如何检查当前运行的shell是否为BusyBox

svl*_*sov 5 linux shell busybox

我试过不同的变种

echo $0
echo $shell
echo $SHELL
ps -p $$
Run Code Online (Sandbox Code Playgroud)

但是没有一个能给出独特的输出.我可以做这样的事情,但它是丑陋和hackish:

if ls --help 2>&1 | grep BusyBox; then
    echo "it is BusyBox"
else
    echo "it is NOT BusyBox"
fi
Run Code Online (Sandbox Code Playgroud)

kon*_*box 6

需要 Linux 和的另一种方式readlink:

#!/bin/ash
exe=`exec 2>/dev/null; readlink "/proc/$$/exe"`
case "$exe" in
*/busybox)
    echo "It's a busybox shell."
    ;;
esac
Run Code Online (Sandbox Code Playgroud)