Article pages now have a discussion option at the bottom (moderated/captcha, but no registration needed)

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")

The form (note the quoting!)

let "<EXPRESSION>"

is identical to the arithmetic evaluation compound command

(( <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

Enter your comment
 
commands/builtin/let.txt · Last modified: 2010/04/24 21:08 by thebonsai
GNU Free Documentation License 1.2
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0