Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Version String Comparison
- X-seq: zsh-users 20969
- From: "TJ Luoma" <luomat@xxxxxxxxx>
- To: "Zsh-Users List" <zsh-users@xxxxxxx>
- Subject: Version String Comparison
- Date: Thu, 19 Nov 2015 17:16:08 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:mime-version:content-type; bh=+guJsuLgEXWn8N8bEm+Q8IldJaMnL9jJXu5WZWdhAKk=; b=AkDiNFF0ppRPF2Tg93o4OydXekz2ooGZLBqxCmLVOJBOIGsziz8YMZXYj0ROh3lPz4 7FtjRa2VRQgvZEeJkhW1aqlyzBqN0iOtFXQ9Kb5wL8piARGwi+hKaHoyZEkerpQjqneR 524rTI9cgyzFJO/cyE9NMM/nX5BB0sewrHqb1Io1dT/gM4ENxc737XRISjcnz0W1MWoF 2LsMAjrSmqcJAyii0CkAKanERgk8AcMMUcADVbR/qPkpTkieVdqCsT7glOwu2W4JC0BN k0+8PrArKATnj8oP8D41ZfhUVwQnD6jtwotQERAB0UIY7L6ZYuLEumtQ8y3s7yu6MRDb hY1A==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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