let
In this page:
let
let evaluates and assigns the result of an arithmetic expression to a variable, similar to $(( )) but as a standalone command. let x=5+3 sets x to 8 without needing $ on the right-hand side. It's an older alternative that's less commonly used today than $(( )) or ((...)).
Note: ((x = 5 + 3)) is the modern equivalent of let x=5+3 and is generally preferred.
Example: let
#!/bin/bash
let x=5+3
echo "x = $x"
let "y = x * 2"
echo "y = $y"
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first: