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

Re: test if a parameter is numeric



On Tue, Feb 20, 2007 at 08:20:01PM +0000, Stephane Chazelas wrote:
> On Tue, Feb 20, 2007 at 08:52:26AM +0100, DervishD wrote:
> [...]
> >     [[ "$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).
> [...]
> 
> rather from ksh.
> 
> POSIXly, you'd write
> 
> case $1 in
>   ("" | *[!0-9]) echo not a number;;

   ("" | *[!0-9]*) echo not a number;;

sorry.

[...]
> Note that zsh extended globbing patterns, though with a
> different syntax are functionnaly equivalent to regexps and has
> may additions over it.
> 
> ERE -> zsh
> .      ?
> *      #
> +      ##
> ?      (|...)
> (...)  (...)
> (..|..)(..|..)
[...]

It can also be said of ksh's globs (same as bash with extglob or
zsh with kshglob)

ERE -> ksh
.      ?
a*     *(a)
a+     +(a)
a?     ?(a)
(a|b)  @(a|b)

recent versions of ksh have more features. There are features in
ksh globs that are not available in zsh's ones like {3}(...),
and likewise in the other direction like <1-10>.

ksh's @(a*b&*c*) can be written in zsh: a*b~^*c* (and not not),
I don't think bash has an equivalent

-- 
Stéphane



Messages sorted by: Reverse Date, Date, Thread, Author