Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: test if a parameter is numeric
- X-seq: zsh-users 11186
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: "Brian K. White" <brian@xxxxxxxxx>
- Subject: Re: test if a parameter is numeric
- Date: Sat, 10 Feb 2007 18:31:53 +0000
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <003d01c74d3f$3bbd7960$6600000a@venti>
- Mail-followup-to: "Brian K. White" <brian@xxxxxxxxx>, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <Xns98D2ADD16C100zzappergmailcom@xxxxxxxxxxx> <070209182939.ZM18654@xxxxxxxxxxxxxxxxxxxxxx> <003d01c74d3f$3bbd7960$6600000a@venti>
- Sender: Stephane Chazelas <stephane_chazelas@xxxxxxxx>
On Sat, Feb 10, 2007 at 01:13:57PM -0500, Brian K. White wrote:
[...]
> typeset -i N="$1" 2>/dev/null
> or if your shell has built in arithmatic (zsh/kash/bash, not plain sh on
> platforms where sh isn't really bash) instead of using a type defined
> variable, using the common age old trick (in any language) of just
> attempting an arithmatic operation, add 0 to the value.
> unset N
> N=$((1+0))
> if $1 was numeric the N will have it, else N will still be unset
[...]
Those approaches will say that "1+1", "a=1", "SECONDS"... are
numbers some with potentially nasty side effects, as for $1 ==
"PATH=0",
$ set 'PATH=0'
$ N=$(($1+0))
$ ls
ls:2: command not found: ls
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author