bash problem

Lynn David Newton plug-discuss@lists.plug.phoenix.az.us
Thu, 30 May 2002 08:05:40 -0700


  hk> Check that you're using bash2 rather than bash
  hk> 1.x.

Somehow I knew you'd know the answer on this one, Hans.
That's *gotta* be it.

I just went to rpmfind.net and verified that the
standard bash distributed with RH 6.2 is version 1.14.
Rats. No wonder everything was breaking.

Because I've always just used ksh, and when I first
tried bash a few years ago everything I tried instantly
broke, I just ignored it and haven't paid any attention
to changes in the world of bash. I didn't know about a
1.nn versus 2.nn.

That explains why some of my stuff kept breaking last
night. Frustrating. It also makes it difficult to plan
classes. Sigh.

There's no chance that system will be upgraded until at
least the break in July, either.

  >> o I'm trying to demonstrate the superiority in
  >> performance using arithmetic evaluation over the old
  >> technique of using eval to increment variables.
  >> 
  >> o The following command line works fine in ksh and also
  >> in bash 2.05-8
  >> 
  >> aa=1; time while ((aa <= 1000)); do ((aa += 1)); done

  hk> BTW, that's an excellent demo. Almost
  hk> instantanteous for the arith eval vs. almost 6
  hk> seconds using expr. 15 sec on my p133, but still
  hk> almost instantaneous for the arith eval version.

Right. I invented that demonstration for a series of
ksh classes I conducted for System Test people and
others who were interested back in 1991 at Motorola
Computer Group. I had them run this from a script:

$ cat shcount
#!/bin/sh
aa=1
while [ $aa -le 1000 ]
do
    aa=`expr $aa + 1`
done
$ time shcount
... some preposterous time ...

Then I had them do the command above. The results even
on a 1991 system were such that it was done by the time
they could get their hand off the return key.

I remember starting to learn shell programming in 1983
and looking through the manual (such as it was in those
days ... this was still in the System V Release 1 era),
and being shocked to find out the shell had no way of
calculating numbers, making it weaker than BASIC. Using
expr is one of the raunchiest kluges I've seen in the
world of computing, since expr is really aimed at
manipulating string data, not a calculator.

It probably would have been more appropriate to use
something like b=`echo $b + 1 | bc` (in the days of
yore before $(...) syntax) or maybe even something
using dc.

But old habits die slowly. Even today I see shell
scripts written using a=`expr $a + 1`. Sigh.

-- 
Lynn David Newton
Phoenix, AZ