LinuxCommandLibrary

let

bash built-in for arithmetic evaluation

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.

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)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community