Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Version String Comparison




I am looking for a zsh way to compare version numbers, which is smart enough to know that, for example

"6.7.0.36" is less than "6.7.0.0044"

I have been using a 'version' function below, which I found somewhere and I _thought_ worked for this scenario, but I'm now finding that it does not:

	INSTALLED_VERSION="6.7.0.36"
	LATEST_VERSION="6.7.0.0044"

function version { echo "$@" | awk -F. '{ printf("28%03d%03d%03d\n", $1,$2,$3,$4); }'; }

	if [ $(version ${LATEST_VERSION}) -le $(version ${INSTALLED_VERSION}) ]
	then
			# No Update Needed
echo "$NAME: Up To Date (Installed: $INSTALLED_VERSION and Latest: $LATEST_VERSION)"
		exit 0
	fi

But that gives me


	Up To Date (Installed: 6.7.0.36 and Latest: 6.7.0.0044)

(I'd also like to be able to compare version strings such as "5.0b5" and "5.0b10")

TjL



Messages sorted by: Reverse Date, Date, Thread, Author