I need to write a shell script that upgrade a package by comparing installed and available version. For example git 2.3 is installed in my machine, I need to upgrade to new version (if available) through shell script.
I tried this:
#!/bin/bash
package_name=git
INSTALLED_VERSION= rpm -q $package_name
AVAILABLE_VERSION= yum --showduplicates list $package_name
echo $INSTALLED_VERSION
echo $AVAILABLE_VERSION
if [ $INSTALLED_VERSION -lt $AVAILABLE_VERSION ] ; then
yum install -y $package_name
fi
# check version:
git --version