How do I multiple, divide, and use modulus in bash shell scripts?



  • Use the mathematics the symbols are `x, ÷, and mod

    Here you can see them use in a shell script, using arithmetic operators x, /, and %

    $ cat arithmetic.sh
    
    # Multiply
    let "sum=10 * 2"
    echo $sum
    
    # Divide
    let "sum=10 / 2"
    echo $sum
    
    # Modulus
    let "sum=10 % 3"
    echo $sum
    

    Running this script give the following results:

    $ ./arithmetic.sh
    20
    5
    1
    

Log in to reply
 

© Lightnetics 2024