代码之家  ›  专栏  ›  技术社区  ›  svlasov

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

  •  7
  • svlasov  · 技术社区  · 11 年前

    我尝试了不同的变体

    echo $0
    echo $shell
    echo $SHELL
    ps -p $$
    

    但它们都不能给出与众不同的输出。我可以做这样的事情,但它既丑陋又粗俗:

    if ls --help 2>&1 | grep BusyBox; then
        echo "it is BusyBox"
    else
        echo "it is NOT BusyBox"
    fi
    
    3 回复  |  直到 11 年前
        1
  •  6
  •   konsolebox    11 年前

    另一种需要Linux和 readlink :

    #!/bin/ash
    exe=`exec 2>/dev/null; readlink "/proc/$$/exe"`
    case "$exe" in
    */busybox)
        echo "It's a busybox shell."
        ;;
    esac
    
        2
  •  2
  •   Vality    11 年前

    我个人赞成:

    if ps ax -o pid,comm | grep `echo $$` | grep busybox ; then
        echo "it is BusyBox"
    fi
    

    这是一个公平的检查,以确保您正在运行busybox shell。

    这是通过让ps生成一个pid与程序名的列表,然后找到我们的pid并检查程序名是否包含busybox来实现的。

        3
  •  0
  •   user3067510    6 年前

    可能并不完美,但我是这样检查的:

    test -h /bin/ls # busybox or other single binary system
    test -h /bin/ls && test `readlink /bin/ls` = busybox # it is busybox
    
    推荐文章