From: "Benjamin R. Haskell" <zsh@benizi.com>
To: TJ Luoma <luomat@gmail.com>
Cc: Zsh-Users List <zsh-users@zsh.org>
Subject: Re: possible 'is-at-least' bug?
Date: Sat, 5 Dec 2015 01:29:46 -0500 [thread overview]
Message-ID: <CAB2RFrTcUWZZRbWqCT+7mZxUp+A5eb=psc46oDXSqrCcPXGVOQ@mail.gmail.com> (raw)
In-Reply-To: <CADjGqHue=fEzyoayraCEZtqzuExyJiGuMjUDHKYtEOu47w6bew@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1714 bytes --]
On Fri, Dec 4, 2015 at 6:45 PM, TJ Luoma <luomat@gmail.com> wrote:
> Thanks to a recent tip from the list, I've started using 'is-at-least' to
> compare version numbers.
>
> However, I seem to have found a situation/edge case where it does not seem
> to work.
>
> I am trying to compare version numbers of software, in this case ImageOptim
> for the Mac.
>
`is-at-least` isn't intended to be that general. From `man zshall`:
is-at-least needed [ present ]
Perform a greater-than-or-equal-to comparison of two strings having
the
format of a zsh version number; that is, a string of numbers and text
with
segments separated by dots or dashes.
To do so would require a great deal more complexity. It'd probably be a
better check for a package manager (where the version strings can be
limited to a specific format).
The version I have installed is '1.6.1a1' where the 'a' is for 'alpha'
>
> There is a newer version '1.6.1b2' where the 'b' is for 'beta'
>
> ##
>
> LATEST_VERSION='1.6.1b2'
>
> INSTALLED_VERSION='1.6.1a1'
>
> autoload is-at-least
>
> is-at-least "$LATEST_VERSION" "$INSTALLED_VERSION"
>
For this specific case, the following seems reasonable:
LATEST_VERSION=1.6.1b2
INSTALLED_VERSION=1.6.1a1
alpha='(#b)([A-Za-z]##)'
is-at-least ${LATEST_VERSION//$~alpha/.$match[1].}
${INSTALLED_VERSION//$~alpha/.$match[1].}
'(#b)' in a pattern activates back references
'##' is the equivalent of '+' in most regular expression libraries
I think both of those require 'EXTENDED_GLOB'
The `~` in $~alpha means treat the contents of $alpha as a pattern, not
just a string to match
The $match[1] is the parenthesized group in the match (so, a string of
alphabetic characters).
--
Best,
Ben
next prev parent reply other threads:[~2015-12-05 6:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-04 23:45 TJ Luoma
2015-12-05 6:29 ` Benjamin R. Haskell [this message]
2015-12-07 10:25 ` Vincent Lefevre
2015-12-10 0:01 ` Bart Schaefer
2015-12-11 11:22 ` Vincent Lefevre
2015-12-12 5:29 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAB2RFrTcUWZZRbWqCT+7mZxUp+A5eb=psc46oDXSqrCcPXGVOQ@mail.gmail.com' \
--to=zsh@benizi.com \
--cc=luomat@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).