expr指令一般用于整數值,但也可用于字元串。一般格式為:
expr argument operator argument
① 用空格隔開每個項;
② 用 \ (反斜杠) 放在 shell 特殊字元前面;
③ 對包含空格和其他特殊字元的字元串要用引号括起來
1、用于數字
$expr 10 + 10
$expr 20 \* 2
2、用于字元串
(1)、計算字串長度
> expr length "this is a test" //output : 14
(2)、抓取字串
> expr substr "this is a test" 3 5 //output : is is
(3)、抓取第一個字元數字串出現的位置
> expr index "sarasara" a //output : 2
原文:
<a href="http://desheng666.blog.163.com/blog/static/4908408220121643953425/">http://desheng666.blog.163.com/blog/static/4908408220121643953425/</a>
<a href="http://blog.csdn.net/adcxf/article/details/3001275">http://blog.csdn.net/adcxf/article/details/3001275</a>