Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: expansion in conditional expression patterns



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