[Top][All Lists]

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

Re: bug in arithmetic expansion

From: pepa65
Subject: Re: bug in arithmetic expansion
Date: Sat, 9 Nov 2019 22:12:51 +0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0

In the arithmetic context, leading zeroes signify an octal base. Had you
used an 8 or 9, you would have gotten a message like:

bash: 08: value too great for base (error token is "08")

when trying: echo $((08))

So it's not a bug, it's a feature; make sure your base-10 numbers don't
have leading zeroes!


On 11/9/19 5:52 PM, Joern Knoll wrote:
> Hallo,
> in playing around with digital keys (integers) which have a simple
> arithmetic check property, I encountered problemsusing bash's arithmetic
> expansion, when ever the used digital substrings have leading zeros. The
> problem shows up already for the simplest operations, namely converting
> a string argument to its numerical value, as shown below.
> With thanks for your attention and best regards, Jörn Knoll
> [tplx99]:/the/knoll > echo $((0123))
> 83
> [tplx99]:/the/knoll > echo $((123))
> 123
> [tplx99]:/the/knoll > echo $((01234))
> 668
> [tplx99]:/the/knoll > echo $((1234))
> 1234

reply via email to

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