判断linux命令是否存在

2019-03-11  本文已影响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

上一篇 下一篇

猜你喜欢

热点阅读