bash error

ken_i_m at ken_i_m at
Sun Nov 28 09:35:42 PST 2004


I've noticed an error that appears once in a while, months ago.  The
script still functions as expected so I kept putting it off until later.
Well, now it is later.

It took a bit to isolate as it only shows up now and then.  Where I
finally found it was in an assignment statement:

  let t_stamp=`date +%H%M`

It returns an error only at certain times.  Evidently, I suspected a
leading zero was the problem as I added a pipe to sed to supress it:

  let t_stamp=`date +%H%M | sed -e s/^0//`

This works during daylight hours.  But recently the program started
running 24/7 and the error showed up again during the midnight hour.
Before going further there is another feature of the error I need to
mention.  It only occurs when the minutes end in 8 or 9.  Now, in trying
a write a simple test case to illustrate what is happening I see more
mis-handling of values.  Obviously there is something about the way bash
treats numeric values I don't get and I am using it wrong and thus
getting unexpected values:

  let foo=047
  let bar=048
  echo $foo $bar

There are actually two errors is the above script snippet.

I own four books on shell programming and have read the bash manpage
numerous times over the past year.  Yet, there is something basic about
the way bash handles numeric values I am not getting.

I am beginning to suspect that this is a dark corner of bash and that is
why I have not found any docs that do a good job of describing it.
Pointers and application of cluestick greatly appreciated.
I reason and act, therefore, ken_i_m
Chief Gadgeteer, Elegant Innovations
Founder, Bozeman Linux Users Group
(406) 581-0495

More information about the lfs-chat mailing list