This is a shell script using git bash. would like to replace the while loop with for loop or to use function.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

This is a shell script using git bash. would like to replace the while loop with for loop or to use function.

 

echo "---------------------------------------"
echo "..........Task 1........."
echo "---------------------------------------"
echo;echo
echo "Enter you name: "
read name
echo -n " WELCOME!!! $name"
echo;echo
#Display to get the user input for number for which multiples are to be found
echo "Enter the number to find multiples:"
read num

#Display the minimum and maximum value of range
echo  "Enter the minimum and maximum range of values to display: "
read min max

#initializing i to minimum value
echo
i=$min
#initialize 0 to index
count=0

#looping from minimum to maximum values given by the user
echo "Multiples of $num in the given range [$min,$max]: "
while [ $i -le $max ]
do

#checking if i value is divisible by the number
  if(($i % $num == 0))
       then
               if(( $i % 2 == 0 ))
       then
           echo "$i"
    ((count++))
#display the multiples in given range

fi fi
((i++))
done
echo "Count of multiples from $min to $max is $count"
#display the count of multiples in  the given range
echo "Thank you"

 

 

O MINGW64:/c/Users/tafad/files
tafad@MARISA MINGW64 ~/files
$ ./task1.sh
Task 1...
Enter you name:
WELCOME !!! T
Enter the number to find multiples:
7
Enter the minimum and maximum range of values to display:
15 60
Multiples of 7 in the given range [15,60]:
28
42
56
Count of multiples from 15 to 60 is 3
Thank you
tafad@MARISA MINGW64 ~/files
$ |
Transcribed Image Text:O MINGW64:/c/Users/tafad/files tafad@MARISA MINGW64 ~/files $ ./task1.sh Task 1... Enter you name: WELCOME !!! T Enter the number to find multiples: 7 Enter the minimum and maximum range of values to display: 15 60 Multiples of 7 in the given range [15,60]: 28 42 56 Count of multiples from 15 to 60 is 3 Thank you tafad@MARISA MINGW64 ~/files $ |
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY