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
					2
				

then incremented:

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

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"
				

and

					$ 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 books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.