0

I am having trouble comparing integers with decimals in bash if/then statement. I am writing a short script that checks the linux version on a system and if it below 7.9 it will create an alert. I have tried changing the comparing operator to something that works. (-lt/-gt, </>, /< />)

#!/bin/bash

linux_version=$(sudo cat /etc/centos-release | cut -b 22-24)
if [ $linux_version -lt 7.9 ]
    echo 'This server needs to be updated to 7.9 Current Version: '$linux_version
then 
    exit 1
else 
    echo 'This server is updated'
    exit 0
fi
Nic3500
  • 8,144
  • 10
  • 29
  • 40
wade730
  • 9
  • 1
  • 2
    Bash doesn't do decimals or floating point numbers, but also a semantic version number is not a decimal. See https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash – jordanm Mar 02 '22 at 18:45
  • Welcome to SO. Please look at the edit I made, it is *much* simpler to read your code formatted like that. Everything on one line is crazy. Couple points **1** you can use https://www.shellcheck.net/ to validate your syntax. **2** your first `echo` line is before the `then` of the `if` statement, move it after. **3** Please take the [tour] and read [ask]. **4** @jordanm 's comment is spot on. – Nic3500 Mar 04 '22 at 04:49

0 Answers0