Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: expansion in conditional expression patterns
- X-seq: zsh-users 14489
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users ml <zsh-users@xxxxxxxxxx>
- Subject: Re: expansion in conditional expression patterns
- Date: Tue, 13 Oct 2009 10:07:10 +0100
- In-reply-to: <F851A022-A342-41EE-9BC8-692B7E7D3025@xxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: CSR
- References: <F851A022-A342-41EE-9BC8-692B7E7D3025@xxxxxxxxxxx>
On Mon, 12 Oct 2009 19:51:14 +0200
Sebastian Stark <seb-zsh@xxxxxxxxxxx> wrote:
> % limit=5
> % if [[ 1 != <2-$limit> ]]; then print outside; fi
> zsh: parse error: condition expected: 1
>
> What part of this do I misunderstand?
Logically this ought to work: parameter substitution is performed before
pattern matching or globbing. However, "<" is rather overloaded and when
the expression is parsed the shell only decides it's a numeric glob if the
expression is in the strict form with digits. It could probably be made
smarter in this case, where "<" can't be a redirection, but as a knock-on
effect pattern matching would have to be made smarter about deciding later
on if the expression was a numeric glob, so it's not entirely trivial.
Your best bet for now is to do numeric comparisons with -ge and -le or with
<= and >= in (( ... )) expressions. You can use an "eval" but that's probably
a bit too ugly for what you're trying to do.
--
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