-1

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
halfer
  • 19,824
  • 17
  • 99
  • 186
  • Please try https://shellcheck.net/ before asking for human assistance. You have basic syntax errors; the proper syntax for capturing the output of a command is `variable=$(command --with arguments)` – tripleee Feb 07 '23 at 08:18

1 Answers1

0

yum can do it for you, just run

yum update -y "$package_name"

and it will update the package if a new version is available.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134