1.1 按照下標(biāo)截取
str="hello world"
#從下標(biāo)1開始,截取3個字符
echo ${str:1:3}
ell
#從下標(biāo)0開始给僵,截取到倒數(shù)第6個
echo ${str::-6}
hello
#從下標(biāo)0開始觅玻,截取5個字符
echo ${str::5}
hello
#從下標(biāo)1開始培漏,截取到末尾
echo ${str:1}
ello world
1.2 字符串長度
str="hello world"
echo ${#str}
11
1.3 字符串刪除
str="hello world"
#從前面刪,匹配到第一個l字符牌柄,相當(dāng)于startWith的最短匹配
echo ${str#h*l}
lo world
#從前面刪除,相當(dāng)于startWith的最長匹配
echo ${str##h*l}
d
#從后面刪除珊佣,相當(dāng)于endWith最短匹配
echo ${str%l*}
hello wor
#從后面刪除,相當(dāng)于endWith最長匹配
echo ${str%%l*}
he
1.4 字符串替換
#替換第一個l
echo ${str/l/L}
heLlo world
#替換所有l(wèi)
echo ${str//l/L}
heLLo worLd