天天看点

expr简介

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>