Reputation: 135
After the shellshock issue detected on Unix systems with bash, I have to create a script as part of my internship in a firm in order to update bash.
Prerequisites to the installation of the updated IBM bash*.rpm are:
I have a problem dealing with the second part, since the true bash version is given by command bash -version
instead of rpm -qi bash
which essentially gives the version/release of the installation package (and not neccessarily the true bash version).
Basically, my script goes like this:
if [[ bash installed ]] ; then
if [[ bash version installed is < 4.2.50 ]] ; then
install bash version 4.2.50
fi
fi
bash -version
returns a lot of text, and I would like to pick out the bash version.
So far, I've used the following command:
$ bash -version | grep version | awk '{print $4}' | head -n 1
That returns :
4.2.50(1)-release
Is there any way to retrieve the real bash version? I've played around with the sed
command with no success.
Upvotes: 1
Views: 2869
Reputation: 289715
I guess you can directly use the $BASH_VERSION
variable:
$ echo "$BASH_VERSION"
4.2.47(1)-release
From man bash
:
Shell Variables
BASH_VERSION
Expands to a string describing the version of this instance of bash.
Then, to check if the version is under or above 4.2.50
you can make use of sort -V
to order them:
$ printf "%s\n%s\n" 4.2.50 $BASH_VERSION | sort -V
4.2.47(1)-release
4.2.50
$ printf "%s\n%s\n" 4.2.50 5.2.33 | sort -V
4.2.50
5.2.33
This should be enough for you to determine if your current bash version is under or above the desired one, just some head
and tail
is needed for the final result.
From man sort
:
-V, --version-sort
natural sort of (version) numbers within text
Upvotes: 1
Reputation: 174706
Seems like you're trying to get output like this,
$ bash -version | awk -F'[ (]' '/version/{print $4;exit}'
4.3.11
Upvotes: 1