我正在编写一个安装脚本,需要Bash 4.x。这个安装脚本也可以在OSX上使用。我知道在Linux系统上可以通过检查echo $BASH_VERSION
环境变量来获取Bash版本,但是在Darwin中该怎么获取Bash版本呢?运行bash --version
会给出:
GNU bash, version 4.3.33(1)-release (x86_64-apple-darwin14.1.0)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
这不是我想要的输出。我只想得到版本号,尤其是主版本号。
echo $BASH_VERSION
输出为3.2.57(1)-release
。这不是你需要的吗?或者它不能被转换成你想要的形式吗? - Jonathan Leffler