Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: test if a parameter is numeric
- X-seq: zsh-users 11212
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Lydgate <zsh@xxxxxxxxxxxxxxxxxx>, zsh-users@xxxxxxxxxx
- Subject: Re: test if a parameter is numeric
- Date: Tue, 20 Feb 2007 20:20:01 +0000
- In-reply-to: <20070220075226.GA11608@DervishD>
- Mail-followup-to: Lydgate <zsh@xxxxxxxxxxxxxxxxxx>, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <Xns98D2ADD16C100zzappergmailcom@xxxxxxxxxxx> <070209182939.ZM18654@xxxxxxxxxxxxxxxxxxxxxx> <003d01c74d3f$3bbd7960$6600000a@venti> <E1HG3Bl-0007Ge-DM@xxxxxxxxxx> <E1HJIfJ-0002Ok-Ql@xxxxxxxxxx> <20070220075226.GA11608@DervishD>
- Sender: Stephane Chazelas <stephane_chazelas@xxxxxxxx>
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;;
(*) echo is a number;;
esac
The equivalent of bash's [[ ... =~ ... ]]
is [[ ... -pcre-match ... ]] which uses perl compatible
regexps.
Note that zsh extended globbing patterns, though with a
different syntax are functionnaly equivalent to regexps and has
may additions over it.
ERE -> zsh
. ?
* #
+ ##
? (|...)
(...) (...)
(..|..)(..|..)
So
[[ $1 == [0-9]## ]]
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author