【问题标题】:How to know command is installed in shell [duplicate]如何知道命令已安装在 shell [重复] 【发布时间】:2016-01-07 03:03:59 【问题描述】: 在xxx.sh中,我需要执行一个命令。但是如果没有找到这个命令,我想抛出一个错误。 if [[ xxxxxxx ]]; then echo "sorry xx command not found" exit 1 fi 【问题讨论】: 标签: shell 【解决方案1】: 来自this answer: 总结: bash 是您的 shell/hashbang,始终使用 hash(用于命令)或 type(考虑内置函数和关键字)。 编写 POSIX 脚本时,使用命令 -v。 【讨论】: