I'm writing a script which requires the Bash version number in a simple short format.
I'm aware of bash --version
, but this gives a long output:
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.
This could be cut down to the bit I want, 4.2.10
, by this:
bash --version | grep "bash" | cut -f 4 -d " " | cut -d "-" -f 1 | cut -d "(" -f 1
However, this feels like it would be prone to break if that message ever changed slightly for whatever reason.
Is there a better way to do this, and what is this better way?