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

Re: strange arithmetic



On Fri, Nov 28, 1997 at 08:04:44PM -0600, Dan Nelson wrote:
> In the last episode (Nov 28), Louis-David Mitterrand said:
> > > > % i=0;while ! [[ $[++i] < 900 ]];do;echo $i;done
> > > > % 1
> > > > % 2
> > > > [...]
> > > > % 90
> > > >
> > > > Is this normal?
> > 
> > Thanks to you and zefram, I guess I've been exposed to Perl for a little
> > too long (the time I could put off learning shell scripting ;-).
> > 
> > And to think I thought I had discovered a bug in mighty zsh ..
> 
> I'm not sure what Perl has to do with your confusion, unless Perl uses
> [[ .. ]] to signify arithmetic evaluation?  I'd check the Perl man
> pages, but as they are split into 35 (!!!!!) sections, I won't.  Thank
> goodness for "man zshall".
> 
> I think [[ ]] is a builtin version of the test command, with more
> testing capabilities.
> 
> You probably wanted to use the (( )) construct in zsh, to do arithmetic
> evaluation of your test.

Aha! Right. I hadn't ventured deep engough in zsh's man pages. Sorry for
taking bandwidth with "should have RTFM'd" questions.

Right now I'm trying to understand bitwise manipulations and every day
that passes I thanks zsh for being such a wonderful prototyping tool. No
need to compile stuff, just type away and here comes the result... The
$[2#10010101] stuff comes real handy there to understand binary format.

Again, congratulations to zsh's developers. It's an awesome concentrate
of intelligence sitting behind that modest '%' prompt.

-- 

     Louis-David Mitterrand
     http://www.aparima.com
     mito@xxxxxxxxxxx



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