The use of Linux expr for strings
1. Get the length of a string
Expr " string " Expr " string " " .* "
2. Find where the string first appears
Expr " Source String " " Sub-string "
3. Extracting a string from a position in a string
Expr " Source String " start position (calculated from 1) Length of extraction
4. Use the pattern Match of the colon to get the number of strings or to extract the matched string, regular expression pattern matching string
Returns the length of the string,expr" string " ". *" gets the string that matches to, Expr" string "\ (. *\). tar.*", which returns the name of the TAR package (not included.) tar. Any name), that is, simply returning the contents of "\ (" and "\")
Report:
Expr Expr match operator: (colon) compares the first argument to the second parameter, unless all patterns are fixed at the beginning of the string, and must be matched according to the Internationalized Basic regular expression (basic regular expression, BRE). That is, only the sequence starting with the first character of the string can be matched by a regular expression. See the Regex (5) and the notes section. Typically,the/usr/bin/expr match operator returns the number of matched bytes,/usr/xpg4/bin/expr0). If the second parameter contains at least one BRE subexpression [\ (... \)], the matching operator returnsthe string corresponding to \1 .
Exit status
As a side-effect of expression evaluation, expr returns the following exit values:
00. 10. 2 for an invalid expression. >2 error occurred.
Linux Expr Command string operation