Linux - Shell - arithmetic expressions - Relational Operators

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

1. Bitwise

  1. Code

    #!/bin/bash
    
    # 关系运算符
    # 结果是 真/假(1/0)
    
    arg1=4
    arg2=5
    
    # 1. <
    result1=$((arg1<arg2))
    echo $result1
    
    # 2. >
    result2=$((arg1>arg2))
    echo $result2
    
    # 3. <=
    result3=$((arg1<=arg2))
    echo $result3
    
    # 4. >=
    result4=$((arg1<=arg2))
    echo $result4
    
    # 5. ==
    result5=$((arg1==arg2))
    echo $result5
    
    # 6. !=
    result6=$((arg1!=arg2))
    echo $result6
    
    # 7. &&
    # 坑: 如果 arg1 为 假, 则 arg2 不会被验证
    result7=$((arg1&&arg2))
    echo $result7
    
    # 8. ||
    # 坑: 如果 arg1 为 真, 则 arg2 不会被验证
    result8=$((arg1||arg2))
    echo $result8

Guess you like

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