From: http://blog.sina.com.cn/s/blog_7c95e5850100zpch.html
Suppose there is a variable var=http://www.linuxidc.com/test.htm
a # Intercept, delete the left character, and leave the right character. echo ${var#*//} where var is the variable name,# number is the operator,*// means delete the first // and all characters to the left from the left to delete http://result is :www.linuxidc.com/test.htm two ## intercept, delete left character, retain right character. echo ${var##*/}##*/ means delete the last (rightmost) / and all characters on the left, starting from the left http://www.linuxidc.com/ result is test.htm three %, delete the right character, leave the left character echo ${var%/* }%/* means starting from the right, deleting the first / and right character result is: http://www.linuxidc.com four %% intercept, delete the right character, leave the left character Echo ${var%%/*}%%/* to start from the right, delete the last (leftmost) one / and right character result is: http: Five start with the first character on the left and the number of characters echo ${ Var:0:5} where the 0 represents the first character on the left,,5 represents 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} where 7 represents the 8th character on the left, starting at the end. The result is :www.linuxidc.com/test.htm seven starting with the first character on the right and the number of characters Echo ${var:0-7:3} where 0-7 Represents the number of characters from the right side, starting with the seventh character,3 . The result is: Test eight start from the first character on the right, until the end. Echo ${var:0-7} means starting from the seventh character on the right until the end. The result is: test.htm Note: (The first character on the left is denoted by 0 , rightThe first character of the edge is represented by 0-1 ) This article originates from the linux commune website (www.linuxidc.com) original link: http://www.linuxidc.com/ Linux/2010-12/30625.htm
String of Shell intercept variable (GO)