代码之家  ›  专栏  ›  技术社区  ›  Kaushal

如何在具有优先级的多个命令中选择一个命令

  •  1
  • Kaushal  · 技术社区  · 7 年前

    我正在尝试创建一个我需要的基本实用程序 supervisord 安装在机器上。但问题是,这取决于用户,他/她是如何安装的,所以在这里,我试图涵盖几乎所有的场景,以获得supervisord命令。

    if [[ -f "/opt/anaconda/bin/supervisord" ]]; then
      RUNNER="/opt/anaconda/bin/supervisord"
    elif [[ -f "/usr/local/bin/supervisord" ]]; then
      RUNNER="/usr/local/bin/supervisord"
    elif [[ -f "/usr/bin/supervisord" ]]; then
      RUNNER="/usr/bin/supervisord"
    elif [[ "$(command -v supervisord)" ]]; then
      RUNNER="supervisord"
    else
      echo "supervisord is not install on this machine"
      exit 1
    fi
    

    我正在寻找任何更好的方法来实现这一点。

    1 回复  |  直到 7 年前
        1
  •  1
  •   janos slartidan    7 年前

    发布的代码检查一些绝对路径, 当它找到一个存在的时候, 它会用的。 这不是个好主意。 您可以期望用户设置 PATH 以正确的方式 supervisord 换句话说,在 一定是第一选择。

    if type supervisord &>/dev/null; then
      RUNNER=supervisord
    elif ...
      ...
    fi