lebensterben / awesome-clear-linux

Let's make Clear Linux distribution great
GNU General Public License v3.0
69 stars 20 forks source link

Fixed Version Check once again #20

Closed ghost closed 3 years ago

ghost commented 3 years ago

Apparently, the previous commit have few problems with version check, especially when the current version have a lower start and higher end or vice versa.

To make sure this commit will fix the issue, here is a test script:

#!/usr/bin/env bash
CURRENT="470.44.10"
LATEST="471.55.10"

  if [ "$(printf '%s\n' "$LATEST" "$CURRENT" | sort -V | head -n1)" != "$LATEST" ]; then 
        echo "CURRENT VERSION IS LESS THAN ${LATEST}"
  else
        echo "CURRENT VERSION IS EQUAL OR GREATER THAN ${LATEST}"
  fi

changing the CURRENT variable from 470 to 480 or from .11 to .50 shouldn't change how the script compare the versions. (This applies if you change the LATEST variable values)

Hopefully this fixes all the issues with the version check and apologies for the last commit.

lebensterben commented 3 years ago

I didn't use sort because I'm not sure how it would be when the two version string as different length.

Great to learn about sort -V.