Sailing Through The World of Linux BASH Scripting – Part III

Download all articles in PDF format with our TecMint Content Subscription and Linux Support Services starting at $10 per month.

Support TecMint: Did you find this tutorial helpful?. Please help to keep it alive by donating. Every cent counts! - Donate Now

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...

6 Responses

  1. dragodan says:

    in 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

  2. 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 .


  3. #!/bin/bash
    while :
    opwords=( ” Sum Difference Product Quotient )
    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

  4. 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?


  5. vujke says:

    just a small correction of the script

    #! /bin/bash
    while [ $i = “y” ]

    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”;;
    echo “Do u want to continue (y/n)) ?”
    read i
    if [ $i != “y” ]

Got something to say? Join the discussion.

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

Join Over 95000+ Linux Users
  1. 77,543
  2. 4,213
  3. 35,218

Enter your email to get latest Linux Howto's