-   Linux - Newbie (
-   -   Compare installed RPM versions using Bash script (

jimwelc 01-10-2005 02:25 PM

Compare installed RPM versions using Bash script
Hello All,

I am a newbie to the UNIX/Linux flavors and I am attempting to create an installer using RPM. Within my script I want to make sure that the systems has an installed vesion of RPM that is equal to or greater than a specified version. The below snippet gets the current version of RPM, but I am not sure how to parse the values to check for correctness.

#===========BEGIN Code snippet ==========

f_Check_RPM_Version() # Checks the installed version of RPM

#Checks to see if the RPM application
#is installed on the system
if [[ -e $ROOT_BIN_RPM || -e $USR_BIN_RPM|| -e $USR_LOCAL_BIN_RPM ]]; then
RPM_VERSION=`rpm -q rpm`

#****NEED to compare versions here *****
#****NEED to compare versions here *****


exit 1

} # end f_Check_RPM_Version()

#===========END Code snippet ==========

Any help you can proved would be greatly appreciated.

Best Regards,

bulliver 01-10-2005 03:24 PM

Just clarification: You want to check if $RPM_VERSION is greater or equal to rpm-4.2-0.69?? Is that right?

jimwelc 01-10-2005 03:30 PM

RE: Compare installed RPM versions using Bash script
Correct. I am looking to check if $RPM_VERSION is greater or equal to rpm_4.2-0.69.


bulliver 01-10-2005 03:49 PM

Note: this is untested...


#****NEED to compare versions here *****


    echo "$RPM_VERSION is too low..."
    echo "$RPM_VERSION is fine"

#****NEED to compare versions here *****

Have a look at for comparison operators in bash...

jimwelc 01-10-2005 04:41 PM

THANKS for your help bulliver. Your code snippet is just what I was looking for. In my attempt I was fudging up the '['. I will be sure to check out that link.

Best Regards,

QICBoy 01-28-2005 11:31 AM

This is a string comparison, so it will fail on rpm_4.12-0.69. Isn't there a more reliable method, like using an rpm command?

jimwelc 01-28-2005 11:40 AM

Using your example....any built RPM has the following format of:

"[Product Name] - [Distribution Type] - [Major Version] . [Minor Version]. [Maintenance-Revision Version] - [Build Version].[Architecture]"

If this format is not followed then all bets are off. In my case what I ended up doing was stripping the [Major Version] . [Minor Version]. [Maintenance-Revision Version] - [Build Version] out of the string and then do a numerical comparison. Messy but I have not found any quick an easy way around this issue. If you come across anything please feel free to post it.


All times are GMT -5. The time now is 11:28 PM.