It is difficult quickly write a logic to compare software version numbers in a more robust way, as they are a lot of corner cases to handle. But this can be easily done in shell using standard GNU tools.
GNU sort command has a special sort option called version sort which can be used to sort version numbers in a quick and more robust way without having to implement this logic on our own.
Below is an example to pick most recent version of an application from a list of available versions.
# returns 4.09rc1 which is most recent version from the input list
echo -e '1.0.1\n1.0\n1.0-beta\n1.0-rc1\n1.1.1\n0.9\n3\n4.09rc1' | sort -rV | head -1
There are other use cases where you have run some custom commands automatically only when an application is upgraded to a newer version and not when downgraded.
Below is an example showing an implementation of this use case,
#below if condition uses sort to get smallest of two versions and compares it with deployed version
#if sort returns current running version, then deployed version is newer and if condition becomes true
#if both the versions are same or deployed version is older then if condition fails.
CURRENT_VERSION=47.9
DEPLOYED_VERSION=48.03
if [ "${DEPLOYED_VERSION}" != "`echo -e "${CURRENT_VERSION}\n${DEPLOYED_VERSION}" | sort -V | head -n1`" ]; then
echo "application is upgraded, running custom commands"
else
echo "application is not changed or downgraded, do nothing"
fi