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

Re: strange arithmetic



Louis-David Mitterrand wrote:
>% i=0;while [[ $[++i] < 900 ]];do;echo $i;done

"<" does a string comparison.  For a numeric comparison, you want "-lt".

>% i=0;while ! [[ $[++i] = 900 ]];do;echo $i;done

"=" (or the preferred "==") also does string comparison.  You should
really use "-eq" here.

I've just noticed that this is exactly the opposite convention from Perl.
I can even see why the difference was historically inevitable.

-zefram



Messages sorted by: Reverse Date, Date, Thread, Author