linux系统中expr命令


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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM