← Back to Bash Course | Chapter 4: Loops | Lesson 5 of 14

let

In this page:

  1. let

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

bash
#!/bin/bash
let x=5+3
echo "x = $x"

let "y = x * 2"
echo "y = $y"

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.