Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: expansion in conditional expression patterns
- X-seq: zsh-users 14491
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users ml <zsh-users@xxxxxxxxxx>
- Subject: Re: expansion in conditional expression patterns
- Date: Tue, 13 Oct 2009 12:59:55 +0100
- In-reply-to: <D59FAFB2-6CC0-4BA6-92F9-698E08293E2C@xxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <F851A022-A342-41EE-9BC8-692B7E7D3025@xxxxxxxxxxx> <20091013100710.27e3c2fb@news01> <D59FAFB2-6CC0-4BA6-92F9-698E08293E2C@xxxxxxxxxxx>
Sebastian Stark wrote:
> I just did this:
>
> if [[ ! ( ($cmdnum -ge 1) && ($cmdnum -le $limit) ) ]]
>
> Maybe I should have asked differently because there might be a better
> solution for what I'm trying to do. I have an array of commands,
> $cmds, and a user supplied $cmdnum. Now I want to check wether the
> user entered a valid number. ($limit would be $#cmds in this example).
>
> Is there a better way to check wether the user entered a) a number and
> b) in the range 1..$#cmds?
I don't think there's anything magic that you're missing. I'd do
something like:
if [[ $cmdnum != <-> || $cmdnum -gt $#cmds ]]; then
# error
fi
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
Messages sorted by:
Reverse Date,
Date,
Thread,
Author