Declaring Integer Variables

As with ordinary variables, integer variables need not be declared. A variable can simply be given an integer value, and then used in an arithmetic expression.

					$ X=12
					$ ((Y=X * 3))
					$ print $Y
					36
				

However, variables can be explicitly declared integer type by using the typeset –i command. The following example sets the DAYS and MONTHS variables to be integer type:

					$ typeset —i DAYS MONTHS=12
				

There is also another command called integer, which is equivalent to typeset –i. It could be used to declare the DAYS and MONTHS variables like this:

					$ integer DAYS MONTHS=12
				

Variables do not have to be explicitly declared integer type to be used in arithmetic expressions. It may improve performance, but what you really gain ...

Get Korn Shell: Unix and Linux Programming Manual, Third Edition, The now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.