Suppose there are variables var=http://www.hao.com/123.htm
One, # Intercept, delete the left character, retain the right character.
Echo ${var#*//}
where Var is the variable name, # is the operator, *// deletes all characters from the first//number and to the left, starting from the left
that is, delete / http
The result is: www.hao.com/123.htm
Second, the # # 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.hao.com/
The result is 123.htm.
.
Third,% 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.hao.com
Four, percent intercept, delete right character, leave left character
Echo ${var%%/*}
%%/* indicates that the last (leftmost) one/number and right character are deleted from the right.
The result is:http:
Start with 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:
.
Six, 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.hao.com/123.htm
Seven , starting with the first character on the right, and the number of characters
Echo ${var:0-7:3}
one of the 0-7 indicates that the seventh character starts at the right, and 3 indicates the number of characters.
The result is: 123
Eight, 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.
Result is: 123.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 "xiangcun168" blog, make sure to keep this source http://xiangcun168.blog.51cto.com/4788340/1692794
String interception of Linux shell scripts