Latest web development tutorials

Linux expr command

Linux expr command

Linux command Daquan Linux command Daquan

expr command is a command-line manual counter variable used to evaluate the expression in UNIX / LINUX under, generally used for integer values, it can also be used for strings.

grammar

expr 表达式

Expression Description:

  • Separated by a space for each item;
  • Use the / (backslash) in front of the shell-specific characters;
  • String use the quotes contain spaces and other special characters enclosed

Examples

1, calculate the length of the string

> expr length “this is a test”
 14

2, Crawl string

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

3, the first crawling position character numeric string that appears

> 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 (使用乘号时,必须用反斜线屏蔽其特定含义。因为shell可能会误解显示星号的意义)
 90
 > expr 30 * 3
 expr: Syntax error

Linux command Daquan Linux command Daquan