LinuxCommandLibrary

let

TLDR

Arithmetic assignment

$ let "x = 5 + 3"
copy
Increment variable
$ let "count++"
copy
Multiple expressions
$ let "a = 1" "b = 2" "c = a + b"
copy
Comparison (exit code)
$ let "5 > 3"
copy
Modulo operation
$ let "result = 10 % 3"
copy

SYNOPSIS

let expression...

DESCRIPTION

let is a Bash built-in for arithmetic evaluation. It performs integer math and comparisons.
The command sets exit status based on expression result. Zero result returns exit code 1.
let evaluates arithmetic.

PARAMETERS

EXPRESSION

Arithmetic expression(s).
Operators:
+, -, *, /, %, ** (power)
++, -- (increment/decrement)
==, !=, <, >, <=, >=
&&, ||, !

CAVEATS

Bash built-in. Integer only. Use (( )) as alternative. Returns 1 if result is 0.

HISTORY

let is a Bash built-in command for arithmetic evaluation, similar to expr but more powerful.

SEE ALSO

bash(1), expr(1), bc(1)

Copied to clipboard