The let Command

Integer arithmetic can be done with the let command and arithmetic expressions. The format for the let command is:

					let "arithmetic-expression"

where arithmetic-expressions can contain constants, operators, and Korn shell variables. Double quotes are used with arithmetic expressions that contain white space or operators that have special meaning to the Korn shell. For example, variable X can be set to the sum of 1+1 like this:

					$ let "X=1 + 1"
					$ print $X

then incremented:

					$ let "X=X + 1"
					$ print $X

Notice that in arithmetic expressions, regular variables can be referenced by name only, and do not have to be preceded by $ for substitution to be performed. Both

					$ let "X=X + 1"


					$ let "X=$X + 1"

are equivalent. The ...

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

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