Shell脚本中如何判断一个命令是否存在
command命令
shell
if command -v java >/dev/null 2>&1; then
echo 'exists java'
else
echo 'no exists java'
fi
if command -v java >/dev/null 2>&1; then
echo 'exists java'
else
echo 'no exists java'
fi
type命令
shell
if type java >/dev/null 2>&1; then
echo 'exists java'
else
echo 'no exists java'
fi
if type java >/dev/null 2>&1; then
echo 'exists java'
else
echo 'no exists java'
fi
hash命令
shell
if hash java 2>/dev/null; then
echo 'exists java'
else
echo 'no exists java'
fi
if hash java 2>/dev/null; then
echo 'exists java'
else
echo 'no exists java'
fi