Suppose there is a variable var=http://www.google.com/test.htm
1, # Intercept, delete the left character, retain the right character.
Echo ${var#*//}
where Var is the variable name and the # is an operator, *//indicates that the first//number and all characters on the left are deleted from the left.
Delete http://
The result is: www.google.com/test.htm
2. # # Intercept, delete the left character, retain the right character.
Echo ${var##*/}
##*/indicates that the last (rightmost) one/number and all characters to the left are deleted from the left.
That is, delete http://www.google.com/
The result is test.htm.
3,% number intercept, delete the right character, leave the left character
Echo ${var%/*}
%/* indicates that the first/second and right characters are deleted from the right.
The result is: http://www.google.com
4, the percent of the interception, delete the right character, the left character remains
Echo ${var%%/*}
%%/* indicates that the last (leftmost) one/number and right character are deleted from the right.
The result is: http:
5, starting from the first few characters on the left, and the number of characters
Echo ${var:0:5}
0 represents the first character on the left and 5 indicates the total number of characters.
The result is: http:
6, starting from the first few characters on the left, until the end.
Echo ${var:7}
7 means that the 8th character on the left begins, until the end.
The result is: www.google.com/test.htm
7, starting from the right of the first few characters, and the number of characters
Echo ${var:0-7:3}
0-7 means that the seventh character starts at the right, and 3 indicates the number of characters.
The result is: test
8, starting from the first few characters on the right, until the end.
Echo ${var:0-7}
The expression starts at the seventh character on the right and continues to the end.
The result is: test.htm
Note: (The first character on the left is denoted by 0, and the first character on the right is denoted by 0-1)
This article is from the "Chaichuan" blog, make sure to keep this source http://chaichuan.blog.51cto.com/7164297/1979331
Linux string Intercept command