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 and the # is an operator, *//indicates that the first//number and all characters on the left are deleted from the left.
Delete http://
The result is: www.linuxidc.com/test.htm
Two # # Intercept, delete the left character, leave 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.linuxidc.com/
The result is test.htm.
Triple Intercept, delete the right character, leave the left character
Echo ${var%} #显示结果sbin/ntpdate
3.2 Delete the longest match by starting with the preceding string
Syntax: ${variables to be tested # #样式}
Instance:
Filename= "/usr/sbin/ntpdate"
Echo ${filename##} #显示结果sbin/ntpdate
3.2 Delete the longest match by starting with the preceding string
Syntax: ${variables to be tested # #样式}
Instance:
Filename= "/usr/sbin/ntpdate"
Echo ${filename##/*/} #显示结果ntpdate
3.3 Starting from behind the string delete the shortest match
Syntax: ${the variable to be measured% style}
Instance:
Filename= "/usr/sbin/ntpdate"
Echo ${filename%/*} #输出结果/usr/sbin
3.4 Delete the longest match by starting from behind the string
Syntax: ${the variable to be measured in percent style}
Instance:
Filename= "Hello/usr/sbin/ntpdate"
Echo ${filename%%/*} #输出结果hello
4. Replace or delete a partial string
4.1 Replace only the first string found
Syntax: ${variables to be tested/style/replace}
Instance:
str= "Hello hello"
Echo ${str/hello/world} #结果为world Hello
4.2 Replace all found style strings
Syntax: ${variables to be tested//style/replace}
Instance:
str= "Hello hello"
Echo ${str/hello/world} #结果为world World
4.3 Delete the first specified string
Syntax: ${the variable to be tested/the string to delete/}
Instance:
str= "Hello hello"
Echo ${str/hello/} #结果为hello
4.4 Delete all the specified strings
Syntax: ${variables to be tested//variables to be deleted/}
Instance:
str= "Hello World Hello"
Echo ${str//hello/} #输出结果为world
5. Command Extensions
Syntax: $ (command)
Example: time=$ (date) equivalent time= ' Date '
6. Arithmetic expansion
Syntax: $ ((arithmetic))
Instance:
echo "a=$ ((5*5))" #结果为a =25
string of Shell intercept variable