zsh-users
 help / color / mirror / code / Atom feed
* Version String Comparison
@ 2015-11-19 22:16 TJ Luoma
  2015-11-20  3:58 ` Daniel Shahaf
  2015-11-20  5:17 ` Matthew Martin
  0 siblings, 2 replies; 3+ messages in thread
From: TJ Luoma @ 2015-11-19 22:16 UTC (permalink / raw)
  To: Zsh-Users List


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-20  5:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-19 22:16 Version String Comparison TJ Luoma
2015-11-20  3:58 ` Daniel Shahaf
2015-11-20  5:17 ` Matthew Martin

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).