Expr can do the following:
Logical operations
Arg1 | Arg2 logic or operation, true return arg1, otherwise return arg2 (null or to determine the true and false parameters, there is a short-circuit function)
Arg1 & arg2 Logic and operation, true return arg1, otherwise return arg2 (null or to determine the parameter is true, short circuit function)
Relational operations
Arg1 = Arg2 (or arg1 = = arg2) returns equal to 1, unequal return 0
Arg1! = arg2 returns 1, equal returns 0
Arg1 > Arg2 is greater than return 1, otherwise returns 0
Arg1 >= arg2 is greater than or equal to return 1, otherwise returns 0
Arg1 < arg2 less than return 1, otherwise return 0
Arg1 <= arg2 is less than or equal to return 1, otherwise returns 0
It is important to note that in a relational operation, only all parameters are numeric and are numerically compared, otherwise, by dictionary order
Arithmetic operations
Arg1 + arg2
Arg1-arg2
Arg1 * arg2
Arg1/arg2
Arg1% arg2
It is important to note that * There are other meanings in the shell, so you need to escape using \*
String manipulation
String:regexp
1) REGEXP represents a regular expression, and the expression implies ^, that is, REGXP is ^regexp;
2) If there is no \ (and \) in the regexp, then the number of matched characters is returned, or the total mismatch returns 0, and if \ (or \) is returned, the string containing the \ (and \) will return, or the mismatch returns null
Match STRING REGEXP
Class String:regexp Same
substr STRING POSITION LENGTH
Returns the substring from position (starting at 1), long length, if position and length are 0, negative, or non-negative, then returns null
Index STRING CHARSET
CharSet can contain more than one character, but only returns the position of the first character in string, and returns 0 if the characters in CharSet are not in string.
Length STRING
Returns the length of a string
+ TOKEN
The token is interpreted as a string, even if token is a keyword, such as expr index index n, because the second index is the keyword of the expr syntax, the error is handled as follows: Expr index + index n
All of the above expressions need to be aware that there must be spaces on both sides of the operator.
The expr command in the shell