String interception from the original address: http://www.jb51.net/article/56563.htm
One: string interception
There are VAR variables:
var=http://www.aaa.com/123.htm
1. # Intercept, delete the left character, leave the right character.
echo ${var#*//}
Www.aaa.com/123.htm
2. # # Intercept, delete the left character and leave the right character.
echo ${var##*/}123. htm
3.% Intercept, delete right character, leave left character
echo ${var%/*}http://www.aaa.com
4. The percent number intercept, delete the right character, leave the left character
echo ${var/*}http:
5. Start 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.
http
6. Starting from the first few characters on the left, until the end
echo ${var:7} 7 means the 8th character on the left begins, until the end. www.aaa.com/123. htm
7. Start with the first few characters on the right and the number of characters
echo ${var:0-7:3} 0-7 means the seventh character starts at the right,3 Represents the number of characters. 123
8. Start with the first few characters on the right and continue to the end.
echo ${var:0-7} #表示从右边第七个字符开始, until the end. 123. htm
To judge a string containing a relationship from: http://www.cnblogs.com/ginsonwang/p/5525340.html
Two: The judgment string contains
1
Stra="Long String"StrB="string"result=$ (echo $strA | grep"${STRB}")if[["$result"!=""]]then Echo"include"ElseEcho"does not contain"fi
2
Stra="helloworld"strB="low"if [[$strA =~ $strB]] Then " contains "else "does not contain " fi
3
A="helloworld"B="low"if [[$A = = * $B * ] ]then " contains "else "does not contain " fi
4
thisstring="1 2 3 4 5" # source string searchstring="1 2" # Search string case in *"$searchString"*) echo Enemy Spot; *) echo nope;; ESA
5
string_a=$1string_b=$2if [[${string_a/${string_b}//} = = $STRING _ A] then was not substring. echo N return0 else is substring. echo Y return1 fi
Shell some methods