It is used to evaluate the value of expression variables in UNIX/LINUX. It is generally used as an integer or a string.
Syntax
Expr expression
Expression description:
- Separate each item with spaces;
- Place the slash (/) before a specific shell character;
- Enclose strings containing spaces and other special characters in quotation marks.
Instance
1. Calculate the string length
> Expr length "this is a test"
14
2. Capture strings
> Expr substr "this is a test" 3 5
Is
3. Capture the position where the first character numeric string appears
> Expr index "sarasara"
2
4. Integer operation
> Expr 14% 9
5
> Expr 10 + 10
20
> Expr 1000 + 900
1900
> Expr 30/3/2
5
> Expr 30/* 3 (when using a multiplication number, you must use a backslash to block its specific meaning. Because shell may misunderstand the meaning of the asterisk)
90
> Expr 30*3
Expr: Syntax error