【问题标题】: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。

    【讨论】:

      猜你喜欢
      • 2017-04-19
      • 2021-12-15
      • 2018-01-31
      • 2017-04-18
      • 2016-11-13
      • 1970-01-01
      • 2018-05-11
      • 2015-04-20
      • 2014-12-23
      相关资源
      最近更新 更多