【问题标题】:Detect if coreutils is installed on mac检测mac上是否安装了coreutils
【发布时间】:2020-05-13 05:56:11
【问题描述】:

如果不使用brew,我如何检测运行我的 bash 脚本的 mac 上是否安装了 coreutils。

这是我的脚本:

#!/usr/bin/env bash

check_bash_version () {
  echo "checking which bash version is installed...."
  sleep 3
  echo "Bash versioncheck completed"
  sleep 1
  if [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then
    echo "You need to be using Bash version =< 4. Please upgrade"
    exit 1
  fi
}

check_coreutils () {
  echo "checking if coreutils is installed...."
  sleep 3
  # what goes here
}

main() {
  # Main function.

  # check if MacOS
  if [[ "$(uname)" == "Darwin" ]]; then
    check_bash_version
    check_coreutils
  fi
}

【问题讨论】:

  • 1.从 coreutils 中选择一个工具。 2. 输出此工具的--version。 3. 检查输出中是否有字符串 GNU。
  • 谢谢@KamilCuk。如果您将评论作为答案,那么我可以接受
  • 不相关。你的错误信息应该是You need to be using bash version &gt;= 4

标签: bash macos gnu-coreutils


【解决方案1】:

通常,GNU 工具的存在是通过使用该工具的 --version 的输出并检查其中是否包含字符串 GNU 来完成的。

【讨论】:

  • 这只有在你用 GNU 版本替换 mac 的旧 BSD 版本的 coreutils 时才有效。如果您通过 homebrew 安装 GNU coreutils,它们不会替换它们,而是安装在一边,在 brew 的文件夹中,并由前缀为 g 的二进制名称调用,例如gcomm 而不是 comm。所以如果例如comm --version 不返回 GNU 字符串,您还应该检查 gcomm --version
猜你喜欢
  • 2016-11-08
  • 1970-01-01
  • 2019-07-29
  • 2011-03-25
  • 2013-01-29
  • 1970-01-01
  • 1970-01-01
  • 2014-09-03
  • 2010-11-05
相关资源
最近更新 更多