分类: LINUX
2007-01-04 10:28:59
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