> inmm=$(( 007 + 1)) ; echo $inmm
8
> inmm=$(( 9 + 1)) ; echo $inmm
10
> inmm=$(( 07 + 1)) ; echo $inmm
8
> inmm=$(( 06 + 1)) ; echo $inmm
7
You'll note that several of the numbers used above have leading zeroes.
This is common when doing arithmetic with months (eg: get today's date, add
one to the month).
Unfortunately, ksh doesn't seem to be able to handle these leading zeroes in
all cases. Specifically, it appears from our experimentation that leading
zeroes in front of an 8 or 9 cause an error:
> inmm=$(( 06 + 09)) ; echo $inmm
ksh: 09: 0403-009 The specified number is not valid for this command.
> inmm=$(( 008 + 1)) ; echo $inmm
ksh: 008 + 1: 0403-009 The specified number is not valid for this command.
> inmm=$(( 009 + 1)) ; echo $inmm
ksh: 009 + 1: 0403-009 The specified number is not valid for this command.
> inmm=$(( 09 + 1)) ; echo $inmm
ksh: 09 + 1: 0403-009 The specified number is not valid for this command.
We discovered this today -- before I report it to IBM, I'd like to know
whether this is a common situation or whether it's unique to our system. Do
other peoples' systems exhibit the same kind of inconsistency?
Bob Menschel
The leading zero indicates an octal number,
and of course 08 and 09 are invalid octal numbers.
Paul Landay
If you modify your KSH program to use the let built-in ksh statement, it
should correct the problem.
Paul's post is correct.
Urban
Thanks. After reading Paul's response I did a little reading (this behavior
is different from the systems I'm used to -- Sequent PTX and SCO Unix, at
least the ksh shells we've used, don't have this automatic octal behavior --
they treat all numbers within (( ... )) as decimal integers unless something
specifically tells them to do octal or other base work).
From that reading, I gathered that the LET command would have the same octal
behavior, no?
Instead, since everything said that if base is not specified, the first use
of a variable sets the base, if I initialize my ksh script with something
like var=9, then the sequence
> mm=getmonth() # returns 2-digit month number
> nextmo=$(( $mm + 1 ))
should do decimal arithmetic rather than octal for months 01-09, yes?
Bob
"Urban A. Haas" <uh...@urbantechnology.com> wrote in message
news:3cd7fb05$1...@nntp01.splitrock.net...
The documentation you have been reading is probably for ksh93.
The default ksh shipped with AIX 5.1 is still the 88 (?) level,
but ksh93 is shipped with AIX 5.1:
ls -l /bin/ksh*
Change the first line to:
#!/bin/ksh93
to use the ksh93 version.
It looks to me like 'let' on the old ksh has the same
octal notation issue as without 'let', but either way
ksh93 does what you want.
Paul Landay