美文网首页
判断linux命令是否存在

判断linux命令是否存在

作者: 疯言疯語 | 来源:发表于2019-03-11 15:24 被阅读0次
参考文档:https://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script


POSIX compatible:
command -v <the_command>

For bash specific environments:
hash <the_command> # For regular commands. Or...
type <the_command> # To check built-ins and keywords


Example:

if $(command -v test11  >/dev/null 2>&1); then
  echo 'exists'
fi

if $(command -v test  >/dev/null 2>&1); then
  echo 'exists'
fi

相关文章

网友评论

      本文标题:判断linux命令是否存在

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