expr

[Calculation][WIN]Expression

Linux expr command syntax

Function: The expr command is a manual command line counter, used to find the value of expression variables under UNIX/LINUX. It is generally used for integer values, but can also be used for strings.

Syntax: expr expression

Linux expr command example

1. Calculate the length of the string

> expr length “this is a test”
 14

2. Fetch the string

> expr substr “this is a test” 3 5
is is

3. Fetch the first occurrence of the character string Position

> expr index "sarasara"  a 
2

4, Integer operation

> expr 14 % 9
 5
 > expr 10 + 10
 20
 > expr 1000 + 900
 1900
 > expr 30 / 3 / 2
 5
 > expr 30 \* 3 (使用乘号时,必须用反斜线屏蔽其特定含义。因为shell可能会误解显示星号的意义)
 90
 > expr 30 * 3
 expr: Syntax error