integer

Official Description

Declares a variable as an integer.

Syntax

integer [variable[=value]]

Options

None

Oddities

integer is an alias for typeset -i.

Makes calculations faster. Shell has to convert strings to integers before performing a calculation.

Example

$ a=17
$ b=22
$
$ time for (( i=0; i<1000; i++ ))
> do
> (( c = $a + $b ))          # Do calculations using strings
> done

real    0m0.26s
user    0m0.26s
sys     0m0.00s
$
$ integer d e f              # Declare variables as integers
$
$ d=17
$ e=22
$
$  time for (( i=0; i<1000; i++ ))
> do
> (( f = e + d ))            # Do calculations using integers
> done

real    0m0.16s              # Much faster
user    0m0.16s
sys     0m0.00s
$
				

Get Korn Shell Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.