let
shellLinux/Unix
The let command is one of the most frequently used commands in Linux/Unix-like operating systems. let Perform arithmetic operations on shell variables
Quick Reference
Command Name:
let
Category:
shell
Platform:
Linux/Unix
Basic Usage:
let [options] [arguments]
Common Use Cases
Syntax
let expression [expression ...]
Options
Operator | Description |
---|---|
id++, id-- |
Post-increment, post-decrement |
++id, --id |
Pre-increment, pre-decrement |
-, + |
Unary minus, plus |
!, ~ |
Logical and bitwise negation |
** |
Exponentiation |
*, /, % |
Multiplication, division, remainder |
+, - |
Addition, subtraction |
<<, >> |
Left and right bitwise shifts |
<=, >=, <, > |
Comparison operators |
==, != |
Equality and inequality |
& |
Bitwise AND |
^ |
Bitwise XOR (exclusive OR) |
| |
Bitwise OR |
&& |
Logical AND |
|| |
Logical OR |
expr ? expr : expr |
Conditional operator (ternary) |
=, *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, |= |
Assignment operators |
expr1 , expr2 |
Comma operator (evaluates both, returns expr2) |
Examples
How to Use These Examples
The examples below show common ways to use the let
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
let a=5