Name

let

Synopsis

    let expressions
            or
    ((expressions))

Perform arithmetic as specified by one or more expressions. expressions consist of numbers, operators, and shell variables (which don’t need a preceding $). Expressions must be quoted if they contain spaces or other special characters. The (()) form does the quoting for you. For more information and examples, see the section "Arithmetic Expressions,” earlier in this chapter. See also expr in Chapter 2.

Examples

Each of these examples adds 1 to variable i:

    i='expr $i + 1'         All Bourne shells
    let i=i+1               Bash 
, ksh
                      

    let "i = i + 1"
    (( i = i + 1 ))
    (( i += 1 ))
    (( i++ ))Bash, ksh93

Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.