I have a bash script for updating a tool which should compare the currently installed version with the latest available version. This always worked until now, where a new version was released, called "4.10.0".
I have tried the following two if statements and both returned the older version (4.9.4) as the newer one:
if [[ $CURRENT_GHOST > $PACKAGE_VERSION_OLD ]]
if [ "$(printf '%s\n' "$CURRENT_GHOST" "$PACKAGE_VERSION_OLD" | sort -V | head -n1)" = "$CURRENT_GHOST" ];
How can I improve it so that even the 4.10.0 gets detected as a newer (higher) version than the older (lower) version 4.9.4?
sort -V
sorts from oldest to newest version - are you sure you don't wanttail -n1
here? – steeldriver Jul 20 '21 at 20:26dpkg --compare-versions 4.10.0 gt 4.9.4
, but then note that there may be differences between the various versioning rules, e.g. in Debian's system1.2.3~xyz
sorts as older than1.2.3
, or1.2.3-abc
. But then,sort -V
seems to also follow that rule. Interesting. – ilkkachu Jul 20 '21 at 20:44