linux中expr命令

 

1、expr命令实现在命令行中的四则运算

[root@centos7pc1 test3]# ls
[root@centos7pc1 test3]# expr 10 + 5   ## 数字和运算符的两侧必须有空格
15
[root@centos7pc1 test3]# expr 10+5
10+5
[root@centos7pc1 test3]# expr 10 +5
expr: syntax error
[root@centos7pc1 test3]# expr 10+ 5
expr: syntax error

 

[root@centos7pc1 test3]# expr 10 - 3    ## 减法运算
7
[root@centos7pc1 test3]# expr 10 * 8    ## 乘法运算
80
[root@centos7pc1 test3]# touch a.txt
[root@centos7pc1 test3]# expr 10 * 8    ## 当当前目录中有文件时, 需要再乘法符号之前加转义符号
expr: syntax error
[root@centos7pc1 test3]# expr 10 \* 8
80
[root@centos7pc1 test3]# expr 10 / 8    ## 除法运算, 地板除法
1

 

2、必须是整数运算

[root@centos7pc1 test3]# expr 3 + 10
13
[root@centos7pc1 test3]# expr 3.5 + 10
expr: non-integer argument

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。