|
${#string}
|
获取$string 字符长度
|
test="12345";echo ${#test}
5
|
|
${string:pos}
|
在$string 中,从位置$pos 开始提取串(pos 从0 开始)
|
test="12345";echo ${test:1}
2345
|
|
${string:pos:length}
|
在$string 中,从位置$pos 开始提取长度为$length 的串
|
test="12345";echo ${test:1:2}
23
|
|
${string#substring}
|
从变量$string 左边, 删除最短匹配$substring的串
|
test="123453467";echo ${test#*3}
453467
|
|
${string##substring}
|
从变量$string 左边, 删除最长匹配$substring的串
|
test="123453467";echo ${test##*3}
467
|
|
${string%substring}
|
从变量$string 的右边开始, 删除最短匹配$substring 的串
|
test="123453467";echo ${test%3*}
12345
|
|
${string%%substring}
|
从变量$string 的右边开始, 删除最长匹配$substring 的串
|
test="123453467";echo ${test%%3*}
12
|
|
${string/substring/replacement}
|
使用$replacement, 来代替第一个匹配的$substring
|
test="123453467";echo ${test/3/9}
129 453467
|
|
${string//substring/replacement}
|
使用$replacement, 代替所有匹配 的$substring
|
test="123453467";echo ${test//3/9}
129 459 467
|
|
${string/#substring/replacement}
|
如果$string 的前缀 匹配 $substring, 那么就用$replacement来代替$substring
|
test="123123467";echo ${test/#123/9}
9 123467
|
|
${string/%substring/replacement}
|
如果$string 的后缀 匹配$substring, 那么就用$replacement来代替$substring
|
test="123123467";echo ${test/%467/9}
1231239
|