How do i use comparison operators in a bash shell script?



  • The comparison operators are <, <=, >, and >=

    Which read:
    < less than
    <= less than or equal to
    > greater than
    >= greater than or equal to

    if (( 10 < 2 ));then
    echo "Running calculation 1, That's true!"
    fi
    
    if (( 10 <= 2 ));then
    echo "Running calculation 2, That's true!"
    fi
    
    if (( 10 > 2 ));then
    echo "Running calculation 3, That's true!"
    fi
    
    if (( 10 >= 2 ));then
    echo "Running calculation 4, That's true!"
    fi
    

    Running the script give the following results:

    $ ./arithmetic.sh
    Running calculation 3, That's true!
    Running calculation 4, That's true!
    

Log in to reply
 

© Lightnetics 2024