77## Description
88
99The ` let ` builtin command evaluates each supplied word from left to
10- right as an [ arithmetic expression] ( / syntax/arith_expr) and returns an
10+ right as an [ arithmetic expression] ( ../../ syntax/arith_expr.md ) and returns an
1111exit code according to the truth value of the rightmost expression.
1212
1313- 0 (TRUE) when ` arg ` evaluated to not 0 (arithmetic \" true\" )
1414- 1 (FALSE) when ` arg ` evaluated to 0 (arithmetic \" false\" )
1515
1616For this return code mapping, please see [ this
17- section] ( / syntax/arith_expr#arithmetic_expressions_and_return_codes) .
17+ section] ( ../../ syntax/arith_expr.md #arithmetic_expressions_and_return_codes) .
1818They work in the same way as ` (( ` .
1919
2020## Examples
2121
22- ` let ` is very similar to [ ((] ( / syntax/ccmd/arithmetic_eval) - the only
22+ ` let ` is very similar to [ ((] ( ../../ syntax/ccmd/arithmetic_eval.md ) - the only
2323difference being ` let ` is a builtin (simple command), and ` (( ` is a
2424compound command. The arguments to ` let ` are therefore subject to all
2525the same expansions and substitutions as any other simple command -
2626requiring proper quoting and escaping - whereas the contents of ` (( `
27- aren\' t subject to [ word-splitting] ( / syntax/expansion/wordsplit) or
28- [ pathname expansion] ( / syntax/expansion/globs) (almost never desirable
27+ aren\' t subject to [ word-splitting] ( ../../ syntax/expansion/wordsplit.md ) or
28+ [ pathname expansion] ( ../../ syntax/expansion/globs.md ) (almost never desirable
2929for arithmetic). For this reason, ** the [ arithmetic compound
30- command] ( / syntax/ccmd/arithmetic_eval) should generally be preferred
30+ command] ( ../../ syntax/ccmd/arithmetic_eval.md ) should generally be preferred
3131over ` let ` ** .
3232
3333 $ let 'b = a' "(a += 3) + $((a = 1)), b++"
3434 $ echo "$a - $b - $?"
3535 4 - 2 - 0
3636
3737Is equivalent to the [ arithmetic evaluation compound
38- command] ( / syntax/ccmd/arithmetic_eval) :
38+ command] ( ../../ syntax/ccmd/arithmetic_eval.md ) :
3939
4040 $ (( b = a, (a += 3) + $((a = 1)), b++ ))
4141 $ echo "$a - $b - $?"
@@ -78,14 +78,14 @@ needed.
7878 ` Aside from differences in supported arithmetic features, this
7979 should be identical to the Bash/Ksh ` let ` .
8080- It seems to be a common misunderstanding that ` let ` has some legacy
81- purpose. Both ` let ` and [[ ^ 1 ] ] ( syntax/ccmd/arithmetic_eval ) were
81+ purpose. Both ` let ` and [[ ^ 1 ] ] ( ../../ syntax/ccmd/arithmetic_eval.md ) were
8282 ksh88 features and almost identical in terms of portability as
8383 everything that inherited one also tended to get the other. Don\' t
8484 choose ` let ` over ` (( ` expecting it to work in more places.
8585- [ expr(1)] ( http://pubs.opengroup.org/onlinepubs/9699919799/utilities/expr.html#tag_20_42 )
8686 is a command one is likely to come across sooner or later. While it
8787 is more \" standard\" than ` let ` , the above should always be
88- preferred. Both [ arithmetic expansion] ( / syntax/arith_expr) s and the
88+ preferred. Both [ arithmetic expansion] ( ../../ syntax/arith_expr.md ) s and the
8989 ` [ ` test operator are specified by POSIX(r) and satisfy almost all
9090 of expr\' s use-cases. Unlike ` let ` , ` expr ` cannot assign directly to
9191 bash variables but instead returns a result on stdout. ` expr ` takes
@@ -96,16 +96,16 @@ needed.
9696 without generating any output other than a return code.
9797- For unknown reasons, ` let ` is one of the Bash commands with special
9898 parsing for arguments formatted like compound array assignments.
99- See: [ eval] ( commands/builtin/eval#portability_considerations ) for
99+ See: [ eval] ( ../../ commands/builtin/eval.md #portability_considerations) for
100100 details. There are no known practical uses for this. Parentheses are
101101 treated as grouping operators and compound assignment is not
102102 possible by arithmetic expressions.
103103
104104## See also
105105
106- - Internal: [ arithmetic expansion] ( / syntax/expansion/arith)
107- - Internal: [ arithmetic expressions] ( / syntax/arith_expr)
106+ - Internal: [ arithmetic expansion] ( ../../ syntax/expansion/arith.md )
107+ - Internal: [ arithmetic expressions] ( ../../ syntax/arith_expr.md )
108108- Internal: [ arithmetic evaluation compound
109- command] ( / syntax/ccmd/arithmetic_eval)
109+ command] ( ../../ syntax/ccmd/arithmetic_eval.md )
110110
111111[ ^ 1 ] : \. ..
0 commit comments