Answer reference:
Suppose there are variables
var=http://www.oldboyedu.com/123.htm.
1. # Intercept, delete the left character, leave the right character.
Variable: Var=http://www.oldboyedu.com/123.htmecho ${var#*//} where Var is the variable name and the # is an operator, *//means to delete the first//number and all characters on the left from the left to remove http://The result is : www.oldboyedu.com/123.htm
2. # # Intercept, delete the left character and leave the right character.
Variable: Var=http://www.oldboyedu.com/123.htmecho ${var##*/}##*/means delete the last (rightmost) one/number and all characters to the left from the left to remove http:// www.oldboyedu.com/result is: 123.htm
3.% Intercept, delete right character, leave left character
Variable: Var=http://www.oldboyedu.com/123.htmecho ${var%/*}%/* means to delete the first/second and right characters from the right,/123.htm result is: http://www.oldboyedu.com
4. The percent number intercept, delete the right character, leave the left character
Variable: Var=http://www.oldboyedu.com/123.htmecho ${var%%/*}%%/* means to delete the last (leftmost) one/number and right character from the right,//www.oldboyedu.com/ 123.htm. The result is: http:
5.: x:y format for string information, starting with the first X characters on the left, and removing the number of y of characters
Variable: Var=http://www.oldboyedu.com/123.htmecho ${var:0:5} where 0 means the first character on the left begins, and 5 represents the total number of characters. That is, take the value from the string of 0 characters to the value of H, take 5 characters, to the character: (colon) The result is: http:
6.: The y format represents the string information, starting from the y+1 character on the left, until the end.
Variable: Var=http://www.oldboyedu.com/123.htmecho ${var:7} where 7 means the 8th character on the left begins, until the end. That is, the value is taken from the 7th bit/after the string, knowing that the end of the string is: www.oldboyedu.com/123.htm
7.: x-y:z format for string information, where X-y represents the range of values of the string, from the right of the X-y character to take the value, and the number of Z-characters to take a character
Variable: Var=http://www.oldboyedu.com/123.htmecho ${var:0-7:3} where 0-7 means the seventh character starts at the right, and 3 indicates the number of characters. The value 0-7 takes 7 bits from the right side of the string and then the top 3 PS from the left: special Instructions ① when 1-7, means 0-7 takes 7 bits, but subtracts 1 bits from the leftmost value, i.e. var=987654321 0-7=987654321 1-7=87654321② when 7-7, Indicates that 0-7 takes 7 bits, but subtracts 7 bits from the leftmost value, that is, var=987654321 0-7=987654321 7-7=987654321③ when the range of values is less than the number of characters in the output, the output is all, that is, var=987654321 0-3=321 takes 4 bits When it is shown that 321 results are: 123
8.: The X-y format represents the string information, where X-y represents the range of values of the string, starting from the No. 0 character on the right and ending at the y-bit.
Variable: Var=http://www.oldboyedu.com/123.htmecho ${var:0-7} means starting from the seventh character on the right until the end. The value 0-7 is taken from the right of the string 7-bit result is: 123.htm Note: (The first character on the left is represented by a single numeric character 0, and the first character on the right is represented by 0-1). Com/123.htm.
Note
Today is the 98th Day of the day to accompany you and look forward to your progress .
For questions and answers, please leave a comment in the blog comments section .
Index of the topic of the previous period
http://lidao.blog.51cto.com/3388056/1914205
This article is from the "Lee blog" blog, make sure to keep this source http://lidao.blog.51cto.com/3388056/1949831
Old boy Education daily-day 98th-shell Knowledge Point: A common use of string interception in shell scripts?