Linux Shell string interception is useful, there are eight ways:
Assuming there are variable var=http://www.aaa.com/123.htm
1. # Intercept, delete left character, keep right character.
Echo ${var#*//}
where Var is the variable name, # is the operator, and *//indicates that the first//number and all characters on the left are deleted from the left
That is, delete http://
The result: www.aaa.com/123.htm
2. # # Intercept, delete left character, keep right character.
Echo ${var##*/}
##*/indicates that the last (rightmost) one/number and all characters on the left are deleted from the left.
That is, delete http://www.aaa.com/
The result is 123.htm.
3.% Intercept, remove the right character, leave the left character
Echo ${var%/*}
%/*, starting from the right, deletes the first/number and the right character
The result: http://www.aaa.com
4.%-percent intercept, delete the right character, leave the left character
Echo ${var%%/*}
%%/*, starting from the right, deletes the last (leftmost) one/number and the right character
The result: http:
5. Starting with the first few characters on the left and the number of characters
Echo ${var:0:5}
0 represents the beginning of the first character on the left, and 5 represents the total number of characters.
The result: http:
6. Start with the first few characters on the left, until the end.
Echo ${var:7}
7 of these represent the beginning of the 8th character on the left, until the end.
The result: www.aaa.com/123.htm
7. Starting with the first few characters on the right and the number of characters
Echo ${var:0-7:3}
0-7 of these represent the start of the seventh character on the right, and 3 for the number of characters.
The result: 123
8. Start with the first few characters on the right, until the end.
Echo ${var:0-7}
Represents the beginning of the seventh character on the right, until the end.
The result: 123.htm
Note: (The first character on the left is represented by 0, and the first character on the right is represented by 0-1).
Original: http://www.runoob.com/linux/linux-shell-variable.html