This is an old revision of the document!


The let builtin

Synopsis

let <EXPRESSION>

Description

The let builtin command evaluates the arithmetic expression <EXPRESSION> and returns the exit codes

  • 0 (TRUE) when <EXPRESSION> evaluated to not 0 (arithmetic "true")
  • 1 (FALSE) when <EXPRESSION> evaluated to 0 (arithmetic "false")

For this return code mapping, please see this section.

The form (note the quoting!)

let "<EXPRESSION>"

is identical to the arithmetic evaluation compound command (except the exit code)

(( <EXPRESSION> ))

This way should be preferred.

Examples

Portability considerations

The let command is not specified by POSIX®. The standard equivalent is:

[ "$(( <EXPRESSION> ))" -ne 0 ]

The quotes around the arithmetic expansion are only necessary with bash and AT&T versions of ksh, other standard shells such as ash, pdksh or zsh derivatives don't have that bug/misfeature.

See also

Discussion

joshua toyota, 2011/01/13 09:33

I believe the internal links to "arithmetic expansion" should be directed here:

http://wiki.bash-hackers.org/syntax/expansion/arith

Instead of:

http://wiki.bash-hackers.org/syntax/arith_expr

Just an fyi...

Jan Schampera, 2011/01/13 17:40

Of course, my bad...

Thanks

Enter your comment. Wiki syntax is allowed: