expr

来源:互联网 发布:合肥行知学校在哪 编辑:程序博客网 时间:2024/04/20 05:58

1、 数字运算

[root@localhost irs]# expr 10 + 10

[root@localhost irs]# expr 30 / 3 / 2

[root@localhost irs]# expr 14 % 9

[root@localhost irs]# expr 30 /* 8

说明:运算符左右都有空格 ,如果没有空格表示是字符串连接;使用乘号时,必须用反斜线屏蔽其特定含义,因为shell可能会误解显示星号的意义。

2、 字符串处理

1)         [root@localhost irs]# expr substr zhongguorenming 6 3

2)         [root@localhost irs]# expr index zhongguorenming ni

3)         [root@localhost irs]# expr length zhongguorenming

4)         [root@localhost irs]# expr match nisjgbicc nisj

说明:index表示参照的任意一个字母在比较对象中第一次出现的位置。

3、 其他

[root@localhost irs]# v_num=2

[root@localhost irs]# expr $v_num+3

2+3

[root@localhost irs]# expr $v_num + 3

5