Linux - Shell - arithmetic expressions - arithmetic

  1. Outline
    1. Based on the shell $ (()) of the arithmetic
  2. background
    1. Review shell script
    2. Make up the numbers right
  3. ready
    1. surroundings
      1. the
        1. centos7

1. arithmetic

  1. Code

    #!/bin/bash
    
    # $(()) 的数学运算, 里面的内容, 被解释为 算数表达式
    # $(()) 内的变量, 可以不加 $
    # 只看 正整数
    
    arg1=4
    arg2=5
    # 算数运算
    # 1. +
    var1=$((arg1+arg2))
    echo $var1
    
    # 2. -
    var2=$((arg1-arg2))
    echo $var2
    
    # 3. *
    var3=$((arg1*arg2))
    echo $var3
    
    # 4. /
    var4=$((arg1/arg2))
    echo $var4
    
    # 5. %
    var5=$((arg1%arg2))
    echo $var5
    

Guess you like

Origin www.cnblogs.com/xy14/p/12090843.html