Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Version String Comparison
- X-seq: zsh-users 20972
- From: Matthew Martin <phy1729@xxxxxxxxx>
- To: TJ Luoma <luomat@xxxxxxxxx>
- Subject: Re: Version String Comparison
- Date: Thu, 19 Nov 2015 23:17:01 -0600
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=uggCyAkpkKFtk1vxJNRzAbZZqZrvQcCRyXY6Smm0SBM=; b=GZbqnkKjbqp5RJJ64ec52Og5a27zs3LNBPI7HHqJp0aSF/eOdOQBN64yXBcQWuTDeV udJIs8nT+ROIjADGrp4VWDmvD4cGpceo5VXUHkKJVR3gk7+hLRuyAv6gLqg35YhMY6fK mC1lBMxc7otT7PTXClG+eSKFcEFDGTKWh2D+OgidlFoboLcuxFPLQxIyv4pZTHm2pn1S OmrNOXPsuIRmBv2UgQHRDEGr5NdJG6mxxfp/0Kqu3JDphwcYqqCoWyHWc0r8B8QSsQOX VLp1aPW3ySWPopnILlJ4qacxfGoGTsjA9gIt3WKiiXeGDetakS/cfmDQyN5WNl00Ayhj j6sQ==
- In-reply-to: <9A09EF7C-A81B-4ED9-A266-C6A53BC98167@gmail.com>
- 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
- References: <9A09EF7C-A81B-4ED9-A266-C6A53BC98167@gmail.com>
On Thu, Nov 19, 2015 at 05:16:08PM -0500, TJ Luoma wrote:
>
> 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"
vercomp() {
[ "$1" = "$2" ] && return
[ "${1%%.*}" -gt "${2%%.*}" ] && return 1
[ "${1%%.*}" -lt "${2%%.*}" ] && return 2
vercomp "${1#*.}" "${2#*.}"
}
% vercomp 3 4; echo $?
2
% vercomp 1 1; echo $?
0
% vercomp 6.7.0.36 6.7.0.0044; echo $?
2
Salt to taste for return values and beta handling (and note no error
handling is done).
Messages sorted by:
Reverse Date,
Date,
Thread,
Author