Search code examples
bashredhatrhel7

How to show in bash script the release of a Red Hat distribution


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.


Solution

  • With RHEL7:

    . /etc/os-release
    echo "${VERSION_ID%.*}"
    

    Output:

    7