Reputation: 11
I have a bash script where I request to add a repository related to the current release I'm running, I have define my variable this way:
RedHat_VER=`rpm -qi --whatprovides /etc/redhat-release | awk '/Version/ {print $3}'`
but in this way I get, i.e. "7.6" but I need to get "7", how can I do that?
Thanks to all who can help me. Best regards,
Alessandro.
Upvotes: 0
Views: 1630
Reputation: 4574
Here's one way :
rpm -qia '*release*' | grep Version | cut -d':' -f2 | tr -d ' ' | cut -d'.' -f1
Another way :
cat /etc/redhat-release | cut -d'.' -f1 | awk '{print $NF}'
Upvotes: 0
Reputation: 5372
You can use lsb_release -r
. The output will be something like this, which is easily parsable:
$ lsb_release -r
Release: 6.10
$
And you can make it easier by using -s
(check man lsb_release
):
$ lsb_release -rs
6.10
$
Upvotes: 0