mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 22:08:59 +00:00
2.1 KiB
2.1 KiB
Name
expr - evaluate expressions
Synopsis
$ expr <expression>
$ expr [--help]
Description
expr evaluates and prints the result of an expression as described below to standard output.
An expression may be any of the following:
expr1 | expr2
expr2
ifexpr1
is falsy,expr1
otherwise.expr1 & expr2
expr1
if neither expression is falsy,0
otherwise.expr1 < expr2
1
ifexpr1
is less thanexpr2
,0
otherwise.expr1 <= expr2
1
ifexpr1
is less than or equal toexpr2
,0
otherwise.expr1 = expr2
1
ifexpr1
is equal toexpr2
,0
otherwise.expr1 = expr2
1
ifexpr1
is not equal toexpr2
,0
otherwise.expr1 => expr2
1
ifexpr1
is greater than or equal toexpr2
,0
otherwise.expr1 > expr2
1
ifexpr1
is greater thanexpr2
,0
otherwise.expr1 + expr2
arithmetic integral sum ofexpr1
andexpr2
.expr1 - expr2
arithmetic integral difference ofexpr1
andexpr2
.expr1 * expr2
arithmetic integral product ofexpr1
andexpr2
.expr1 / expr2
arithmetic integral quotient ofexpr1
divided byexpr2
.expr1 % expr2
arithmetic integral quotient ofexpr1
divided byexpr2
.expr1 : expr2
pattern match ofexpr2
as a regular expression inexpr1
- currently not implemented.match expr1 expr2
same asexpr1 : expr2
.substr expr1 expr2 expr3
substring with lengthexpr3
ofexpr1
, starting atexpr2
, indices starting at 1.index expr1 expr2
index ofexpr2
inexpr1
, starting at 1. 0 if not found.length expr1
length of the stringexpr1
+ token
interprettoken
as a string, regardless of whether it is a keyword or an operator.( expr )
value ofexpr
Note that many operators will need to be escaped or quoted if used from within a shell. "falsy" means either the number 0, or the empty string.
Options
--help
: Prints usage information and exits.
Examples
$ expr 1 + 2 * 3 # = 7
$ expr \( 1 + 2 \) = 3 # = 1
$ expr substr foobar 1 3 # foo