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

Re: math, percentage




----- Original Message ----- From: "John Reese" <john.reese@xxxxxxxxx>
To: "Brian K. White" <brian@xxxxxxxxx>
Sent: Wednesday, January 04, 2006 6:05 PM
Subject: Re: math, percentage


Nice.
Never knew you could do the assignment inside the braces like that,
but even so I should have thought to at least try tp=$((t*100/T)) since I
use n=$((n+1)) a hundred times a day.

thanks
Brian K. White  --  brian@xxxxxxxxx  --  http://www.aljex.com/bkw/

You could do
((n++))
instead and save three hundred characters a day.

----

Ah, neat. :)

It should be noted though:

Up to to this point the examples also work in ksh88 ,the version of ksh still shipping stock with many commercial unii as /bin/ksh.

((n++)) does not work in ksh88.
It does work in ksh93, bash, pdksh, and of course zsh.

Most of my fancier scripts need to explicitly call a particular shell anways because of special features, so this is useful.

Brian K. White  --  brian@xxxxxxxxx  --  http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro  BBx    Linux  SCO  FreeBSD    #callahans  Satriani  Filk!


-----
<off topic here but it should be explained why ksh93 doesn't obviate ksh88 and thereby the portability comment>

The existence and availability of ksh93 for most platforms, even though it even ships stock with a few very recent ones (but still not as /bin/ksh), must not be considered as the simple answer for anything that doesn't work in ksh88 though because it's a bit buggy on some systems and cannot be used as the drop in replacement for the stock sh or ksh or as roots or even a users login shell. Ask me how I know. :) It seems ok at first but after a few days in production with a couple hundred users you realize you are having a lot of scattered problems you didn't used to have, and putting the old binary back ends the trend.

It's useful enough though to install it somewhere and call it explicitly on the bang line. My biggest item about ksh93 lately is that it has a built-in sleep that takes floating point values. I have things that really do want a "sleep .1", and anything that wants that, by definition also really wants it built-in, not to fork a child and load an executable every time. No other shell anywhere has that that I've found. (hint!) Perl has nap() and probably other popular non bourne scripting languages have some form of usleep or sleep .xx but heck, so what? So does C.
Also there is:
VARS="look at all these assignments woohoo read is cool how many lines of code would this be without it I ask you montoyo inigra"
   grep "^${LOGNAME}:" /path/to/userdefs | IFS=: read junk $VARS
   export $VARS
   echo $woohoo

The bugginess of ksh93 on the system above is at least partly due to the at&t build system for ksh that is such a pain in the ___ that hardly anyone even attempts to build it, and fewer succeed. For SCO Open Server 5.x.x and lower, there is exactly one binary out there, made by one guy a few years ago, and it's a little buggy, and he knew it all along, and he's not attempting to play with it again. I tried but ran into problems that I couldn't debug because the convoluted build system hid and buried the real problem too well and I actually have a job that doesn't allow me a couple of solid weeks just to build a new shell. :) So it's possible that ksh93 itself is fine and merely it's difficult to do a thorough job of porting it. Either way, it still means you can't count on it.



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