美文网首页
在shell中判断某个可执行程序是否存在

在shell中判断某个可执行程序是否存在

作者: 菜鸟瞎编 | 来源:发表于2019-07-30 13:12 被阅读0次
    $ command -v foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed.  Aborting."; exit 1; }
    $ type foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed.  Aborting."; exit 1; }
    $ hash foo 2>/dev/null || { echo >&2 "I require foo but it's not installed.  Aborting."; exit 1; }
    
    if which brew 2>/dev/null; then
      echo "brew exists!"
    else
      echo "nope, no brew installed."
    fi
    

    详见:https://segmentfault.com/q/1010000000156870

    相关文章

      网友评论

          本文标题:在shell中判断某个可执行程序是否存在

          本文链接:https://www.haomeiwen.com/subject/ywogrctx.html