bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: value too great for base (error token is "0008")


From: Greg Wooledge
Subject: Re: value too great for base (error token is "0008")
Date: Thu, 5 Nov 2009 08:16:20 -0500
User-agent: Mutt/1.4.2.3i

On Wed, Nov 04, 2009 at 11:26:56PM +0100, Dobromir Romankiewicz wrote:
> Thank you for your answers, I'll check more carefully before I'll send next 
> bug report - if I'll find it, of course.
> That was silly. For my excuse I just would like to say I'm not coder.

Heh.  I *am* a coder, and I've been tripped up by leading zeroes causing
a value to be treated as octal in more than one language.  (Bash and Tcl.)
It's a subtle and difficult thing to guard against, in these typeless
or weakly-typed scripting languages.

> The point here was that 2 kinds of variables were needed. Integer number as 
> while counter, and 4 digits string, as a part of filenames - i had add 
> leading zeros to get this working with filesystem I can't change or even 
> list.

The general approach here is that whenever you're dealing with something
as a number, you must not have any leading zeroes on it; or you must
force bash to treat it as base 10, with the "10#" prefix.  Then, when
you're all done with the arithmetic and you're ready to put the number
in a filename, use printf to pad it to however wide you need.  Thus,

n=10
n=$(($n * 3 + 7)) # whatever
filename=app$(printf %05d $n).log




reply via email to

[Prev in Thread] Current Thread [Next in Thread]