Re: Bash Adding 09 or 9.1 etc
- From: Geoff Gigg <di874@xxxxxx>
- Date: Sat, 28 Oct 2006 10:18:47 -0400
Keith wrote:
I have a script that gives a error in BASH whenever I try to add 01-09
with 1.
X="09"
X=$((X+1))
line 42: 09: value too great for base (error token is "09")
This is caused by a date command variable and I'm trying to avoid having to make other changes in the script.
I had the same problem. Solved most easily by forcing BASH to treat the number as decimal, instead of defaulting to octal because of leading 0. How to force it? From BASH manpage:
Constants with a leading 0 are interpreted as octal numbers. A leading
0x or 0X denotes hexadecimal. Otherwise, numbers take the form
[base#]n, where base is a decimal number between 2 and 64 representing
the arithmetic base, and n is a number in that base.
$ x="09"
$ let y=5+x
bash: let: 09: value too great for base (error token is "09")
$ let y=5+10#x
bash: let: y=5+10#x: value too great for base (error token is "10#x")
$ let y=5+10#$x
$ echo $y
14
So you have to use the 10#$x format for your suspect variablesin your let statements to force the base 10 caclulation.
Geoff
.
- References:
- Bash Adding 09 or 9.1 etc
- From: Keith
- Bash Adding 09 or 9.1 etc
- Prev by Date: Re: return values from a function call
- Next by Date: Using the grep command to filter
- Previous by thread: Re: Bash Adding 09 or 9.1 etc
- Next by thread: cut
- Index(es):