How do I add and subtract using bash shell script.



  • Adding.

    let sum="10 + 1"
    echo "10 + 1, That's legs $sum."
    

    Running this script gives:

    $ ./addsub.sh
    10 + 1, That's legs 11.
    

    In the let statement change + for a minus.

    Subtract.

    let sum="10 - 1"
    echo "10  - 1, That's $sum, Doctor's Orders."
    

    Running this script gives:

    $ ./addsub.sh
    10 - 1, That's 9, Doctor's Orders.
    

Log in to reply
 

© Lightnetics 2024