Zsh Mailing List Archive
Messages sorted by:
Re: test if a parameter is numeric
- X-seq: zsh-users 11210
- From: DervishD <zsh@xxxxxxxxxxxx>
- To: Lydgate <zsh@xxxxxxxxxxxxxxxxxx>
- Subject: Re: test if a parameter is numeric
- Date: Tue, 20 Feb 2007 08:52:26 +0100
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <E1HJIfJ-0002Ok-Ql@xxxxxxxxxx>
- Mail-followup-to: Lydgate <zsh@xxxxxxxxxxxxxxxxxx>, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: DervishD
- References: <Xns98D2ADD16C100zzappergmailcom@xxxxxxxxxxx> <070209182939.ZM18654@xxxxxxxxxxxxxxxxxxxxxx> <003d01c74d3f$3bbd7960$6600000a@venti> <E1HG3Bl-0007Ge-DM@xxxxxxxxxx> <E1HJIfJ-0002Ok-Ql@xxxxxxxxxx>
Hi Lydgate :)
* Lydgate <zsh@xxxxxxxxxxxxxxxxxx> dixit:
> On Sun, Feb 11, 2007 at 02:08:40AM +0100, DervishD wrote:
> > If you can use "expr", you can do it with "expr", using simple
> > regexes. OK, not the fastest method, but should do and should do it
> > pretty fast. I use this approach in my "mobs" project. Being bulletproof
> > using almost-portable shell scripting is, at least, tricky. And probably
> > impossible, for what I've seen...
> Sorry maybe I'm missing something, but if you need to match more than
> one digit, what's wrong with:
> [[ "$1" == [0-9][0-9]* ]]
> Which I think is more portable?
If you are considering the second part as a regex, then the above is
definitely NON portable. It's not even POSIX.
But the second part is not a regex, but a shell globbing pattern.
That means that the above will match something like "1234abcd", for
example, and ONLY if the file exists. Otherwise it won't match anything.
In addition to this, if the expansion is not successful, some shells
may substitute nothing in the second part, leaving you with the invalid
[[ "$1" == ]]
And the "[[" is NOT portable, either, it's a zsh thing (and probably
bash has too, I don't know, but AFAIK is not POSIX/SuS).
Raúl Núñez de Arenas Coronado
Linux Registered User 88736 | http://www.dervishd.net
It's my PC and I'll cry if I want to... RAmen!
Messages sorted by: