Linux expr命令

Linux expr命令

expr命令是一个手工命令行计数器,用于在UNIX/LINUX下求表达式变量的值,一般用于整数值,也可用于字符串。

语法

expr 表达式

表达式说明:

  • 用空格隔开每个项;
  • 用 / (反斜杠) 放在 shell 特定的字符前面;
  • 对包含空格和其他特殊字符的字符串要用引号括起来

实例

1、计算字串长度

[root@iZbp143t3oxhfc3ar7jey0Z ~]# expr length "wgr test"
8
[root@iZbp143t3oxhfc3ar7jey0Z ~]#

2、抓取字串

[root@iZbp143t3oxhfc3ar7jey0Z ~]# expr substr "wgr test" 3 5
r tes
[root@iZbp143t3oxhfc3ar7jey0Z ~]#

3、抓取第一个字符数字串出现的位置

[root@iZbp143t3oxhfc3ar7jey0Z ~]# expr index "wgr test" t
5
[root@iZbp143t3oxhfc3ar7jey0Z ~]#

4、整数运算

[root@iZbp143t3oxhfc3ar7jey0Z ~]# expr 14 % 9
5
[root@iZbp143t3oxhfc3ar7jey0Z ~]# expr 10 + 10
20
[root@iZbp143t3oxhfc3ar7jey0Z ~]# expr 30 / 3 / 2
5
[root@iZbp143t3oxhfc3ar7jey0Z ~]# expr 30 / 3 / 2^C
[root@iZbp143t3oxhfc3ar7jey0Z ~]#
[root@iZbp143t3oxhfc3ar7jey0Z ~]# expr 30 \* 3
90
[root@iZbp143t3oxhfc3ar7jey0Z ~]# 
posted @ 2020-04-15 19:53  天宇轩-王  阅读(240)  评论(0编辑  收藏  举报