[PLUG] bash decimal interpretation

Jeme A Brelin jeme at brelin.net
Wed Dec 3 01:58:01 UTC 2003


I have to write little bash loops all the time.  Usually, this is just to
handle bulk renames and things.  Fairly frequently, I have to deal with
this booger:

jbrelin at person:~/$ for a in `seq -w 1 10`;do b=$[$a+5];echo $a $b;done
01 6
02 7
03 8
04 9
05 10
06 11
07 12
bash: 08: value too great for base (error token is "08")

What's the deal with that crap?

OK, it makes perfect sense.  Bash is interpreting numbers that begin with
0 as octal... says so right in the man page.  But why in all of heaven
would it go ahead and do that when the number CAN'T be octal?!?

And I can't find a simple way to treat the number correctly.

Also, how am I supposed to pad that with 0s to get the right length again?
I mean, I could go ahead and do some garbage where I check the length and
add leading 0s until it gets up there, but that seems absurd and doesn't
help in the general case when you don't know what the greatest length is
going to be until you're at the end of the loop.

Grrr.

J.
-- 
   -----------------
     Jeme A Brelin
    jeme at brelin.net
   -----------------
 [cc] counter-copyright
 http://www.openlaw.org




More information about the PLUG mailing list