#!/bin/bash
function compare_versions
{ 
    # Check if two arguments are given
    if [ $# -ne 2 ]; then
        echo "Please provide two version numbers to compare"
    return 1
    fi

    # Assign arguments to local variables
    local ver1=$1
    local ver2=$2

    # Remove dots and pad with zeros
    ver1=${ver1//./}
    ver2=${ver2//./}
    printf -v ver1 "%-4s" "$ver1"
    printf -v ver2 "%-4s" "$ver2"
    ver1=${ver1// /0}
    ver2=${ver2// /0}

    # Compare as integers and return result
    if [ $ver1 -lt $ver2 ]; then
        return -1
    elif [ $ver1 -gt $ver2 ]; then
        return 1
    else
        return 0
    fi
}
