Doing very simple math in bash fails if a number begins with a zero (0).
The short script below illustrates the problem:
--- begin
#!/bin/bash
#Testing number decrement because I ran into an errors
#e.g., lastmo=$((${lastmo}-1)) returns error:
# 09:
Could not find any groups other than this for bash problems. My build is
failing with
make[1]: Leaving directory `/home/users/tovrea/BASH/build_sgi_bash/lib/tilde'
rm -f bash
/home/users/tovrea/local/sgi6/bin/gcc -L./builtins -L./lib/readline
-L./lib/readline -L./lib/glob -L./lib/tilde
ken wrote:
Doing very simple math in bash fails if a number begins with a zero (0).
Thanks for the report. However it isn't a bug but simply a
misunderstanding. Numbers starting with 0 are octal numbers not
decial numbers. And as you know octal numbers includes zero through
seven but does not
Chet Ramey wrote:
Note that [[ and [ return different results when the vars are unquoted.
Yes. There are two differences.
First, the operands in [[ do not undergo all word expansions. The
arguments to [, since it's a builtin, do. That doesn't really matter
to this example, but it's worth
Could not find any groups other than this for bash problems. My build is
failing with
make[1]: Leaving directory `/home/users/tovrea/BASH/build_sgi_bash/lib/tilde'
rm -f bash
/home/users/tovrea/local/sgi6/bin/gcc -L./builtins -L./lib/readline
-L./lib/readline -L./lib/glob -L./lib/tilde
ken wrote:
Doing very simple math in bash fails if a number begins with a zero (0).
The short script below illustrates the problem:
---
Normally, a leading 0 begins an octal constant (I have been bitten
by this in the past as well...).
Where are you getting the value 'lastmo' from?
If from
On Tue, 1 Sep 2009, Linda Walsh wrote:
ken wrote:
Doing very simple math in bash fails if a number begins with a zero (0).
The short script below illustrates the problem:
---
Normally, a leading 0 begins an octal constant (I have been bitten
by this in the past as well...).
Where are
On Tue, 1 Sep 2009, ken wrote:
Doing very simple math in bash fails if a number begins with a zero (0).
Numbers beginning with 0 are base 8 (octal). 08 and 09 are not
valid octal numbers.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
ken wrote:
This is what I get on Linux running on an i686.
Bash should be smart enough to know that 09 = 9
-- and it does sometimes, but not all the time.
Surprise!!
From the bash manual:
Constants with a leading 0 are interpreted as octal numbers. A leading 0x
or 0X denotes hexadecimal.