分类:
2010-03-05 17:39:05
zhyfly: ~$ x="this is a test"
zhyfly: ~$ echo ${#x}
14
zhyfly: ~$ x="this is a test"
zhyfly: ~$ expr length "$x"
14
zhyfly: ~$ x="this is a test"
zhyfly: ~$ expr "$x" : ".*"
14
zhyfly: ~$ x="this is a test"
zhyfly: ~$ expr index "$x" "is"
3
zhyfly: ~$ expr index "$x" "t"
1
zhyfly: ~$ x="this is a test"
zhyfly: ~$ echo ${x:1:5}
his i
zhyfly: ~$ x="this is a test"
zhyfly: ~$ expr substr "$x" 1 5
this
zhyfly: ~$ x="this is a test"
zhyfly: ~$ expr match "$x" "his"
0
zhyfly: ~$ expr match "$x" "this"
4
zhyfly: ~$ expr match "$x" "."
1
zhyfly: ~$ x="this is a test"
zhyfly: ~$ echo ${x#t}
his is a test
zhyfly: ~$ echo ${x#t*h}
is is a test
zhyfly: ~$ echo ${x#t*s}
is a test
zhyfly: ~$ echo ${x##t*s}
t
zhyfly: ~$ echo ${x%t}
this is a tes
zhyfly: ~$ echo ${x%s*t}
this is a te
zhyfly: ~$ echo ${x%e*t}
this is a t
zhyfly: ~$ echo ${x%%i*t}
th
zhyfly: ~$ x="this is a test"
zhyfly: ~$ echo ${x/i/m}
thms is a test
zhyfly: ~$ echo ${x//i/m}
thms ms a test