%x="abcd"
#方法一
%expr length $x
4
# 方法二
%echo ${#x}
4
# 方法三
%expr "$x" : ".*"
4
# expr 的帮助
# STRING : REGEXP anchored pattern match of REGEXP in STRING
%expr index $x "b"
2
%expr index $x "a"
1
%expr index $x "b"
2
%expr index $x "c"
3
%expr index $x "d"
4
# 方法一
# expr startpos length
%expr substr "$x" 1 3
abc
%expr substr "$x" 1 5
abcd
%expr substr "$x" 2 5
bcd
# 方法二
# ${x:pos:lenght}
%echo ${x:1}
bcd
%echo ${x:2}
cd
%echo ${x:0}
abcd
%echo ${x:0:2}
ab
%pos=1
%len=2
%echo ${x:$pos:$len}
bc
# 打印匹配长度
%expr match $x "."
1
%expr match $x "abc"
3
%expr match $x "bc"
0
%x=aabbaarealwwvvww
%echo "${x%w*w}"
aabbaarealwwvv
%echo "${x%%w*w}"
aabbaareal
%echo "${x##a*a}"
lwwvvww
%echo "${x#a*a}"
bbaarealwwvvww