NCEP CCS Conversion Guide |
Issues Converting to AIX 5.1 |
Back to Main Page |
Topic: Arithmetic Evaluation in Korn Shell with Leading Zeroes | |
Posted by: Stephen Gilbert
Updated by: David Michaud |
Post Date: 08/21/2002
Last Updated: 08/22/2002 |
Problem: If using the newval=$((var1*var2))
syntax in ksh to multiply two integer values, any value with a leading
zero ( e.g. typeset -Z2 a; a=8 OR a=08) is interpreted as an octal value.
It is interpreted as a decimal value on asp/bsp.
For exmple:
$((07*08)) returs a ksh error on snow/frost since 8 is not a valid octal
value
The comand syntax above is the same as using the let command as in let "newval=var1*var2". Solution: This change occurs between AIX4 and AIX5 because ksh88 was fixed to conform to POSIX standard. Therefore, the behavior in AIX5 is expected. To get around this issue you can do one of two things. If you are doing string manipulation and want to drop the leading zeroes intentionally, you can do a "typeset -LZ" for the variable you are storing the value in. Or, you can use the expr command. However, using expr causes ksh to fork a child process which will be slower than the ksh arithmetic substitution. Example: var1=07
Change
or Add this before your arithmetic substitution
|
Back to Main Page |