Using the let command for arithmetic
We can use the bash built-in command let
for performing arithmetic operations.
To get more information about let
, type the following:
$ help let
This should produce the following output of this command:

Let's start using the let
command:
$ value=6$ let value=value+1$ echo $value7$ let "value=value+4"$ echo $value11$ let "value+=1"#above expression evaluates as value=value+1$ echo $value12
A summary of operators available with the let
command follows:
- Operation:
Operator
- Unary minus:
-
- Unary plus:
+
- Logical NOT:
!
- Bitwise NOT (negation):
~
- Multiply:
*
- Divide:
/
- Remainder:
%
- Subtract:
-
- Add:
+
Prior to Bash 2.x, the following operators were not available:
- Bitwise left shift:
<<
- Bitwise right shift:
>>
- Equal to and not equal to:
==
,!=
- Comparison operators:
<=, >=, <, >
- Bitwise
AND
:&
- Bitwise
OR
:|
- Bitwise exclusive
OR
:^
- Logical
AND
:&&
- Logical
OR
:||
- Assignment and shortcut assignment:
= *=/= %= -= += >>= <<= &= |= ^=