简体   繁体   English

检测mac上是否安装了coreutils

[英]Detect if coreutils is installed on mac

Without using brew , how can I detect if coreutils is installed on the mac where my bash script is running.如果不使用brew ,我如何检测 coreutils 是否安装在我的 bash 脚本运行的 Mac 上。

here is my script:这是我的脚本:

#!/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
}

Usually the existence of GNU tools is done by using the output of --version from the tool and checking if it has the string GNU in it.通常 GNU 工具的存在是通过使用来自该工具的--version的 output 并检查它是否包含字符串GNU来完成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM