Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: test if a parameter is numeric



    Hi Brian :)

 * Brian K. White <brian@xxxxxxxxx> dixit:
> 
> ----- Original Message ----- 
> From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
> To: <zsh-users@xxxxxxxxxx>
> Sent: Friday, February 09, 2007 9:29 PM
> Subject: Re: test if a parameter is numeric
> 
> 
> >On Feb 9,  5:05pm, zzapper wrote:
> >}
> >} I just want to test if a parameter is numeric
> >}
> >} if [[ "$1" == [0-9] ]]
> >
> >Better:
> >
> > if [[ "$1" = <-> ]]
> >
> >This is a zsh-ism, so it's not cross-shell portable, but the pattern <->
> >matches any string having any number of digits and only digits.
> 
> ksh, legacy sco/sun/etc  sh, bash etc...

    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...

    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: Reverse Date, Date, Thread, Author