Basic Linux Tutorial
Computer Tutorial

The let command

The let command

The let command performs both arithmetic and logic operations. The use of the let command is important because all loops depend on the control variable. The value of this control must be changed during the execution of the loop. Usually this value is incremented or decremented with the help of the let command. The loop structures also need logic operations, used for the testing value of the control variable. This is the second use of the let command. Like the test command, the let command also has explicit and implicit modes.

Explicit Mode let Command :
In the explicit mode, the word let is used in the command line. Consider the following example of the use of the command.

$ B = 3
$ let " C = A + B "
$ echo $ C

Implicit Mode let Command

You can replace the word let with double parentheses on each side of the expression. The above example, where you added two variables, can also be accomplished as follows.

$ A = 5
$ B = 3
$ ( ( C = A + B ) )
$ echo $ C

While evaluating the result of an expression, the usual arithmetic rules are applied. Parentheses can be used to alter the order of evaluation.

Operators Used with the let Command

Operator Description
- Unary minus
! Unary negation (same value but with a negative sign)
= Assignment
+ Addition
- Subtraction
* Multiplication
/ Integer division
% Remainder
< Less than
> Greater than
< = Less than or equal to
> = Greater than or equal to
= = Comparison for equality
! = Comparison for none quality