我正在編寫一個腳本,它需要簡單短格式的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