如何获取bash版本号
发布时间:2020-12-15 19:34:25 所属栏目:安全 来源:网络整理
导读:我正在编写一个脚本,需要一个简单的短格式的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
我正在编写一个脚本,需要一个简单的短格式的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 shell中运行,则应该设置$ BASH_VERSION环境变量:
$ echo $BASH_VERSION 4.2.8(1)-release 这应该更容易和更可靠地解析。有关由shell设置的环境变量列表,请参阅man page。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |