Operating System - Linux
1753569 Members
5731 Online
108796 Solutions
New Discussion юеВ

math error under 11.23 (perceived as octal?)

 
SOLVED
Go to solution
Scott Lindstrom_2
Regular Advisor

math error under 11.23 (perceived as octal?)

I have the following code the works under 11.11 (using /usr/bin/sh):

TODAYS_JULIAN_DATE=$(date +%j) (this yields '018' today)

This statement then executes OK:

((whatever=$TODAYS_JULIAN_DATE-$LAST_LOGIN_JULIAN_DATE))

This resolves to: (( whatever=018-16 ))

However, under 11.23 the previous statement gives the following error message:

sh: 018-16 : The specified number is not valid for this command

I'm guessing the shell sees '018' as an octal number, rather than a decimal number. (Not sure if that's a valid guess).

Any ideas on what I could do so this script works under both 11.11 and 11.23?

TIA,
Scott
3 REPLIES 3
Patrick Wallek
Honored Contributor
Solution

Re: math error under 11.23 (perceived as octal?)

Use typeset to declare your variable types. Do a 'man sh-posix' and search for typeset for more information.

typeset -i TODAYS_JULIAN_DATE
typeset -i LAST_LOGIN_JULIAN_DATE
TODAYS_JULIAN_DATE=$(date +%j)
LAST_LOGIN_JULIAN_DATE=$(whatever you use to get 16)
((whatever=$TODAYS_JULIAN_DATE-$LAST_LOGIN_JULIAN_DATE))

echo ${whatever}
Scott Lindstrom_2
Regular Advisor

Re: math error under 11.23 (perceived as octal?)

Patrick -

That works great! Thanks for the help!

(This is probably the 10th-12th time I've had to make a script change moving from 11.11 to 11.23. Whatever happened to backwards compatibility? AAARRRRGGGGGHHHH!)

Scott
Scott Lindstrom_2
Regular Advisor

Re: math error under 11.23 (perceived as octal?)

Patrick's solution solved my problem.