3

I would like to treat a number with leading zero as a decimal with the least effort so I intend to use the following syntax:

x=08
y=$(( 10#$x - 1 ))

Will the following syntax work on ksh88?

xuesheng
  • 133

1 Answers1

3

Appears so:

$ command -v ksh
/usr/bin/ksh
$ what /usr/bin/ksh
/usr/bin/ksh:
        Version M-11/16/88i
        SunOS 5.8 Generic 110662-24 Apr 2007
$ ksh

$ x=08
$ y=$(( 10#$x - 1 ))
$ echo "$x - $y"
08 - 7

From the "Arithmetic Evaluation" section of the man page:

Constants are of the form [ base# ] n where base is a decimal number between two and thirty-six representing the arithmetic base and n is a number in that base. If base is omitted then base 10 is used.

glenn jackman
  • 85,964