1 #!/bin/bash
2
3 str= "Http://www.baidu.com/test.htm"
4
5 #echo ${str}
The result of the operation is:http://www.baidu.com/test.htm
Method One: #截取, delete the left character, leave the right character
Echo ${str#*//}
#*//means to delete the first//number and all characters on the left from the left, that is, delete http://
The result of the operation is:www.baidu.com/test.htm
Method Two: # #截取, delete the left character, leave the right character
Echo ${str##*/}
##*/means to delete the last/(i.e. rightmost/) and all characters on the left
The result of the operation is: test.htm
Method Three:% intercept, delete right character, preserve left character
Echo ${str%/*}
%/* means to remove all characters from the first/and right, starting at the far right
The result of the operation is:http://www.baidu.com
Method Four: Percent intercept, delete the right character, leave the left character
Echo ${str%%/*}
%%/* means delete the last/(leftmost/start) and all characters to the right starting from the right
Run Result:http:
Method Five: Start with the first few characters on the left and the number of characters
Echo ${str:0:5}
0 means starting with the first character on the left and 5 representing the total number of characters
The result of the operation is:http:
Method Six: Start from the first character of the coordinates until the end of the string
Echo ${str:7}
7 means starting from the eighth character of a string until the end of the string
The result of the operation is:www.baidu.com/test.htm
Method Seven: Start with the first few characters on the right and the number of characters
Echo ${str:0-7:3}
0-7 means starting with the first character on the right and 3 representing the number of characters
Run Result:est
Method Eight: Start from the first character on the right to the end
Echo ${str:0-7}
Starts at the seventh character on the right, until the end
The result of the operation is:est.htm
String interception of shell scripts under Linux