1、linux系统中expr命令实现命令行中的四则运算
简单示例:
[root@linuxprobe test]# expr 5 + 3 ## 在命令行中实现加法运算
8
2、中间必须有空格
[root@linuxprobe test]# expr 5+3 ##中间必须有空格
5+3
[root@linuxprobe test]# expr 5 +3 ##同上
expr: Syntax error: unexpected argument ‘+3’
[root@linuxprobe test]# expr 5+ 3 ## 同上
expr: Syntax error: unexpected argument ‘3’
3、必须是整数运算
[root@linuxprobe test]# expr 5 + 3
8
[root@linuxprobe test]# expr 5.5 + 3 ## 必须是整数运算
expr: non-integer argument
4、减法运算
[root@linuxprobe test]# expr 10 - 4
6
[root@linuxprobe test]# expr 10 + 5 - 2
13
5、乘法运算
[root@linuxprobe test]# ls
[root@linuxprobe test]# expr 3 * 5 ## 当前目录为空时,*前可以不加转义
15
[root@linuxprobe test]# touch a.txt
[root@linuxprobe test]# ls
a.txt
[root@linuxprobe test]# expr 3 * 5
expr: Syntax error: unexpected argument ‘a.txt’
[root@linuxprobe test]# expr 3 \* 5 ## 加转义
15
6、除法、取余
[root@linuxprobe test]# expr 10 / 2
5
[root@linuxprobe test]# expr 10 / 3 ## 除法只保留整数
3
[root@linuxprobe test]# expr 10 % 3 ##取余数
1
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。