zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    第五次博客作业
    第三次博客作业
    个人简介
    实验三
    实验二
    实验一
    《构建之法》心得体会
    第三次博客园作业
    软件测试实验二
    个人简历
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/13811393.html
Copyright © 2011-2022 走看看