Sailing Through The World of Linux BASH Scripting – Part III

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Use our Linode referral link if you plan to buy VPS (it starts at only $10/month).
  4. Support us via PayPal donate - Make a Donation
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux course in 5 Days

We are thankful for your never ending support.

Receive Your Free Complimentary eBook NOW! -

Download Free Linux eBooks

Advanced Bash-Scripting Guide
Linux Bible
A Newbie's Getting Started Guide to Linux
Introduction to Linux - A Hands on Guide

You may also like...

7 Responses

  1. vgon says:

    #!/bin/bash
    while :
    do
    ops==+-*/
    opwords=( ” Sum Difference Product Quotient )
    sum=0
    read -ep “Enter first no.: ” n1
    read -ep “Enter second no.: ” n2
    printf “%d. %s\n” 1 Addition 2 Subtraction 3 Multiplication 4 Division
    read -sn1 -ep “Enter your choice: ” ch
    (( ch > 0 && ch < 5 )) &&
    printf '%s: %d\n' "${opwords[ch]}" "$(( n1 ${ops:ch:1} n2 ))" ||
    echo "Invalid choice"
    read -sn1 -ep "Do you want to continue (y/n)?" i
    [[ $i != "y" ]] && exit
    done

  2. dragodan says:

    in up.sh script, why it is needed to have exec /bin/bash at the end. I tried without last line and it does not work.

    Thanks in advance

  3. Saravanan says:

    Hi Team ,

    Can you please explain how the rcmd command is working & how can i run multiple commands on remote machine by using the rcmd command. It will be useful if get the reply with the new post .

    Regards,
    Saravanan

  4. #!/bin/bash
    while :
    do
    ops==+-*/
    opwords=( ” Sum Difference Product Quotient )
    sum=0
    read -ep “Enter first no.: ” n1
    read -ep “Enter second no.: ” n2
    printf “%d. %s\n” 1 Addition 2 Subtraction 3 Multiplication 4 Division
    read -sn1 -ep “Enter your choice: ” ch
    (( ch > 0 && ch < 5 )) &&
    printf '%s: %d\n' "${opwords[ch]}" "$(( n1 ${ops:ch:1} n2 ))" ||
    echo "Invalid choice"
    read -sn1 -ep "Do you want to continue (y/n)?" i
    [[ $i != "y" ]] && exit
    done

  5. Chris says:

    How can an article using expr for arithmetic (especially with #!/bin/bash as the shebang) be taken seriously?

    if [ $i != “y” ] is unnecessary.

    • Richard says:

      Hi Chris,

      Could you elaborate? How would you change it? The test is inherent to the while statement and thus not needed. Correct?

      rc

  6. vujke says:

    just a small correction of the script

    #! /bin/bash
    clear
    i=”y”
    while [ $i = “y” ]
    do
    sum=0

    echo ” Enter one no.”
    read n1
    echo “Enter second no.”
    read n2

    echo “1.Addition”
    echo “2.Subtraction”
    echo “3.Multiplication”
    echo “4.Division”
    echo “Enter your choice”
    read ch
    case $ch in
    1)sum=`expr $n1 + $n2`
    echo “Sum =”$sum;;
    2)sum=`expr $n1 – $n2`
    echo “Sub = “$sum;;
    3)sum=`expr $n1 \* $n2`
    echo “Mul = “$sum;;
    4)sum=`expr $n1 / $n2`
    echo “Div = “$sum;;
    *)echo “Invalid choice”;;
    esac
    echo “Do u want to continue (y/n)) ?”
    read i
    if [ $i != “y” ]
    then
    exit
    fi
    done

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

Join Over 150K+ Linux Users
  1. 100,756
  2. 5,113
  3. 36,418

Enter your email to get latest Linux Howto's