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

 

posted @ 2022-04-02 11:57  小鲨鱼2018  阅读(597)  评论(0编辑  收藏  举报