1828622 Members
1411 Online
109983 Solutions
New Discussion

Strange sh Behavior

 
SOLVED
Go to solution
spex
Honored Contributor

Strange sh Behavior

While working on a shell script which outputs time in HH:MM:SS format based on total seconds elapsed, I encountered something strange. I would appreciate it if someone could explain this behavior exhibited by sh-posix and sh-bourne under HP-UX 11.00:

# echo $(( 00 ))
0
# echo $(( 01 ))
1
# echo $(( 02 ))
2
# echo $(( 03 ))
3
# echo $(( 04 ))
4
# echo $(( 05 ))
5
# echo $(( 06 ))
6
# echo $(( 07 ))
7
# echo $(( 08 ))
sh: 08 : The specified number is not valid for this command.
# echo $(( 09 ))
sh: 09 : The specified number is not valid for this command.
# echo $(( 10 ))
10
# echo $(( 11 ))
11

ksh does not exhibit this behavior.

PCS
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor
Solution

Re: Strange sh Behavior

Hi:

A leading zero (0) in the a shell script specifies OCTAL values. Your first tip is that eight (8) isn't valid -- it isn't in octal :-))

Regards!

...JRF...
spex
Honored Contributor

Re: Strange sh Behavior

James,

Thank you!

PCS
spex
Honored Contributor

Re: Strange sh Behavior

Thread closed.
Dennis Handly
Acclaimed Contributor

Re: Strange sh Behavior

JRF wrote:
>A leading zero (0) in the a shell script specifies OCTAL values

You can solve this by specifying the base:
echo $(( 10#08 ))