Usage: ${str%word} #最大限度的获取word左边的子串 ${str%%word} # Minimum gets the substring ${str#word} to the left of Word #最大限度的获取word右边的子串 ${str# #word} #最小限度的获取word右边的子串 ${#str} #获取字符串长度
Example:
file= "Abc.def.ghi"
#最大限度获取. * substring on the left
> a=${file%.*}
> Echo $a
abc.def
#最小限度获取. * Left substring
> a=${file%%.*}
> Echo $a
ABC
#最大限度获取 *. substring on right side
> a=${file#*.}
> Echo $a
def.ghi
#最小限度获取 *. substring on the right
> a=${file##*.}
> Echo $a
ghi
#获取长度
> length=${#file}
> Echo $length
#################### ################################
#字符串下标从0开始, 0 represents the first character, and 0-1 represents the first character on the right
##################################
the ################## #从左边第2个 (the array subscript 1) starts the interception, intercepting the length of 2
> Echo ${file:1:2}
BC
#从左边第2个开始截取到结尾
> Echo ${file:1}
Bc.def.ghi
#从右边第三个开始截取, intercept length 2
> Echo ${file:0-3:2}
gh
# From the right third start intercept to the end
> Echo ${file:0-3}
Ghi