Syntax 1:substring=${string:start:len}
The subscript of string starts with 0, with start, but the Len character is truncated and assigned to substring
1 #!/bin/bash2 #substr =${string: Start:len}3 str=" 123456789 " 4 substr=${str:3:3}5echo $substr6 7 Output: 8 456
Syntax 2: intercepting a specified string
${varible##*string}: The string after the last string is truncated from left to right
${varible#*string}: The string after the first string is truncated from left to right
${varible%%string*}: The string after the last string is intercepted from right to left
${varible%string*}: The string after the first string is intercepted from right to left
"*": just a wildcard character can not
1#!/bin/Bash2 3Str="Usr/bin/user"4#* ${varible##*string}5substr1=${str##*/}6echo $substr 1 # =User7 8#* ${varible#*string}9substr2=${str#*/}Tenecho $substr 2 # = bin/User One A#* ${varible%%string*} -substr3=${str%%/*} - echo $substr 3 # = usr the - #* ${varible%string*} - substr4=${str%/*} - echo $substr 4 # = Usr/bin
Shell String Segmentation