mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 01:42:44 +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- expr2if- expr1is falsy,- expr1otherwise.
- expr1 & expr2- expr1if neither expression is falsy,- 0otherwise.
- expr1 < expr2- 1if- expr1is less than- expr2,- 0otherwise.
- expr1 <= expr2- 1if- expr1is less than or equal to- expr2,- 0otherwise.
- expr1 = expr2- 1if- expr1is equal to- expr2,- 0otherwise.
- expr1 = expr2- 1if- expr1is not equal to- expr2,- 0otherwise.
- expr1 => expr2- 1if- expr1is greater than or equal to- expr2,- 0otherwise.
- expr1 > expr2- 1if- expr1is greater than- expr2,- 0otherwise.
- expr1 + expr2arithmetic integral sum of- expr1and- expr2.
- expr1 - expr2arithmetic integral difference of- expr1and- expr2.
- expr1 * expr2arithmetic integral product of- expr1and- expr2.
- expr1 / expr2arithmetic integral quotient of- expr1divided by- expr2.
- expr1 % expr2arithmetic integral quotient of- expr1divided by- expr2.
- expr1 : expr2pattern match of- expr2as a regular expression in- expr1- currently not implemented.
- match expr1 expr2same as- expr1 : expr2.
- substr expr1 expr2 expr3substring with length- expr3of- expr1, starting at- expr2, indices starting at 1.
- index expr1 expr2index of- expr2in- expr1, starting at 1. 0 if not found.
- length expr1length of the string- expr1
- + tokeninterpret- tokenas a string, regardless of whether it is a keyword or an operator.
- ( expr )value of- expr
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
