From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: zsh-users@sunsite.dk
Subject: Re: test if a parameter is numeric
Date: Sat, 10 Feb 2007 08:35:11 +0000 [thread overview]
Message-ID: <20070210083511.GA4522@sc.homeunix.net> (raw)
In-Reply-To: <070209182939.ZM18654@torch.brasslantern.com>
On Fri, Feb 09, 2007 at 06:29:38PM -0800, Bart Schaefer wrote:
> 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.
I was under the impression that zzapper was looking for
something to match *one* *decimal* digit though.
For positive decimal numbers, <-> will do (unless you don't want
to consider 09 or numbers greater than your max interger as
valid numbers).
To check for signed integer constants expressed in any notation
recognized by zsh (like 0xa, 8#77, 012 (being 10 or 12 depending
on "octalzeroes")...), it's a bit more tricky.
By the way, are those normal:
$ echo $((40#^))
39
(given that ^ is also an arithmetic operator)?
$ echo $((02#11))
3
$ setopt octalzeroes
$ echo $((02#11))
zsh: bad math expression: operator expected at `#11'
$
--
Stéphane
next prev parent reply other threads:[~2007-02-10 8:35 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-09 17:05 zzapper
2007-02-10 2:29 ` Bart Schaefer
2007-02-10 8:35 ` Stephane Chazelas [this message]
2007-02-10 19:22 ` Bart Schaefer
2007-02-10 20:38 ` Stephane Chazelas
2007-02-10 18:13 ` Brian K. White
2007-02-10 18:31 ` Stephane Chazelas
2007-02-11 1:08 ` DervishD
[not found] ` <E1HG3Bl-0007Ge-DM@e4ward.com>
2007-02-20 0:14 ` Lydgate
2007-02-20 3:21 ` Andrew Ruder
[not found] ` <E1HJLZy-0001UA-44@b.e4ward.com>
2007-02-20 3:56 ` zsh
2007-02-20 7:02 ` Com MN PG P E B Consultant 3
2007-02-20 7:52 ` DervishD
2007-02-20 14:35 ` Frank Terbeck
2007-02-20 20:20 ` Stephane Chazelas
2007-02-20 21:35 ` Stephane Chazelas
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=20070210083511.GA4522@sc.homeunix.net \
--to=stephane_chazelas@yahoo.fr \
--cc=zsh-users@sunsite.dk \
/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).