String manipulation
${#string} The number of characters in the output sentence
${string:position:length} output $position The length of the start of the character
${string:position}
[[email protected] scripts]# liuyifei=] i like sanpan i like luo Swimming "[[email protected] scripts]# echo ${#liuyifei}33[[email protected] Scripts]# echo ${liuyifei:2:4}like[[email protected] scripts]# echo ${liuyifei:2 } like sanpan i like luo swimming==== above measured ${ String#substring} is retrieved from the front of the string, as long as the match to the character begins to delete the shortest match ${string# #substring} from the beginning to the longest delete ${string%substring} starts at the end of ${string%%substring} from the end, Similar to above ##====== must be matched from the beginning on [[Email protected] scripts]# echo ${liuyifei#like}i like sanpan i like luo swimming[[email protected] scripts]# echo ${ Liuyifei#*like}sanpan i like luo swimming[[email protected] scripts]# echo ${liuyifei##*like}luo swimming[[email protected] scripts]# echo ${liuyifei%*like} i like sanpan i like luo swimming[[email protected] scripts]# echo ${ Liuyifei%like} i like sanpan i like luo swimming[[email protected] scripts]# echo ${liuyifei%like*}i like sanpan i[[email protected] Scripts]# echo ${liuyifei%%like*}i
========================
${string/substring/replace} replaces the first encountered match character
${string/#substring/replace} prefix match, must match all, replace a strip
${string/%substring/replace} forward, replace the last encountered match character, must match all
[[email protected] scripts]# echo ${liuyifei/like/love}
I love Sanpan i like Luo swimming
[[email protected] scripts]# echo ${liuyifei/#*like/love}
Love Luo swimming
[[email protected] scripts]# echo ${liuyifei/%like*/love}
I love
Personal Summary: #% appears in the shell variable operation must always be matched for related operations
Common operations of variable quantum strings in shell scripts