English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The expr command is a manual command-line counter used to calculate the value of expression variables under UNIX/LINUX, generally used for integer values, but can also be used for strings.
expr Expression
Expression Description:
Separate each item with a space;
Use a backslash \ before shell-specific characters;
Use quotes to enclose strings containing spaces and other special characters
1. Calculate the length of the string
> expr length "this is a test" 14
2. Capture the string
> expr substr "this is a test" 3 5 is is
3. Capture the position of the first character string occurrence
> expr index "sarasara" a 2
4. Integer Arithmetic
> expr 14 % 9 5 > expr 10 + 10 20 > expr 1000 + 900 1900 > expr 30 / 3 / 2 5 > expr 30 * 3 (It is necessary to use a backslash to shield the specific meaning of the asterisk when using the multiplication sign. Because the shell may misunderstand the meaning of the asterisk displayed) 90 > expr 30 * 3 expr: Syntax error