From f5f12eed551f6fcbf0040b13268c054c1d8786c6 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Wed, 24 Jan 2018 13:46:20 +0800 Subject: dfly-update: implement compare_version() using "sort -V" --- dfly-update | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/dfly-update b/dfly-update index 04cec61..7b8744e 100755 --- a/dfly-update +++ b/dfly-update @@ -129,12 +129,23 @@ get_version_filename() { } # Compare between two version strings +# Parameters: ver1 ver2 # Returns values: -# * 0 : The two versions are the same -# * 1 : The first version is older than the other one -# * 2 : The first version is newer than the other one +# * 0 : ver1 = ver2 +# * 1 : ver1 < ver2 +# * 2 : ver1 > ver2 compare_version() { - echo 1 + lcal ver1 ver2 ver_low + ver1="$1" + ver2="$2" + ver_low=$(echo -e "${ver1}\n${ver2}" | sort -V | head -n 1) + if [ "${ver1}" = "${ver2}" ]; then + echo 0 + elif [ "${ver1}" = "${ver_low}" ]; then + echo 1 + else + echo 2 + fi } -- cgit v1.2.2