美文网首页
SHELL 判断一个命令行是否存在

SHELL 判断一个命令行是否存在

作者: 姚小帅 | 来源:发表于2019-05-14 19:22 被阅读0次

利用shell内建的type命令来判断一个命令行是否存在

hasCommandByType(){
    if type $1 2>/dev/null; 
    then
        return 1
    else
        return 0
    fi
}
hasCommandByType quickgame
returnVue=$?
echo $returnVue
if [ $returnVue == 0 ] ;
then
    echo "尚未安装oppo quickgame工具,跳过OPPO小游戏生成流程"
    exit 0
fi

参考:http://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script/677212#677212

相关文章

网友评论

      本文标题:SHELL 判断一个命令行是否存在

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