我正在编写一个脚本,它需要简单短格式的bash版本号。如何获得bash版本号
我所知道的bash --version
,但是这给长期输出:
GNU bash, version 4.2.10(1)-release (i686-pc-linux-gnu)
Copyright (C) 2011 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.
这可以被砍倒在一点我想,4.2.10
,本:
bash --version | grep "bash" | cut -f 4 -d " " | cut -d "-" -f 1 | cut -d "(" -f 1
然而,如果这个消息由于某种原因而稍微改变,这感觉就像是容易中断。
有没有更好的方法来做到这一点,这是什么更好的方法?
感谢
......并与我发现'$ BASH_VERSINFO'与我可以只用我所需要的比特构建它,出于某种原因,我的机器上的手册页没有提及它设置的环境变量。谢谢:) – stwalkerster 2012-02-26 05:10:21