English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The expr command is a manual command-line counter used in UNIX/To get the value of an expression variable under LINUX, it is generally used for integer values, and can also be used for strings.
expr Expression
Expression Description:
Items are separated by spaces;
Use the backslash \ before shell-specific characters;
Strings containing spaces and other special characters should be enclosed in quotes
1Calculate the length of the string
> expr length "this is a test" 14
2Extract the string
> expr substr "this is a test" 3 5 is is
3Find the position of the first occurrence of the character string
> expr index "sarasara" a 2
4Integer Arithmetic
> expr 14 % 9 5 > expr 10 + 10 20 > expr 1000 + 900 1900 > expr 30 / 3 / 2 5 > expr 30 \* 3 (When using the asterisk, it must be escaped to avoid its special meaning. Because the shell may misunderstand the meaning of the asterisk.) 90 > expr 30 * 3 expr: Syntax error