Trying to write a basic shell script of the below question using GITBASH. Every time l try to run the code l get a syntax error, need help om how to fix this. below is the code. Find the even multiples of any number chosen by the user in a given range – the user should specify the multiples of which number they want to print and a minimum and maximum value. The multiples printed should be within the [minimum, maximum] range. For example, if the user choses the number 7 and would like to print all even multiples in the [15, 60] range, the program should print all the even multiples that are bigger than or equal to 15 (minimum), but smaller than or equal to 60 (maximum). The program should keep a count of how many numbers were printed and should output that count, as well as the numbers. The output then, for the example given, should be 28, 42, 56, and the count should be 3.    #.sh code echo "Enter the number to find multiples:" read num echo  "Enter the minimum and maximum range of values to display: " read min max echo count=0 #initialize index to 0 for (( i=$min; i <= $max; i+=2 )) do echo result[$count]=$i # If the i value is divisible by the number given and i is even then i is stored in result array ((count++)) #Increment count value by 1 ((i++)) #increment i value by 1 echo "Multiples in given range[$min,$max] : ${result[@]}" #Display the Multiples in the given range echo "Count of multiples is $count" #Display the count of multiples in the given range done

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

Trying to write a basic shell script of the below question using GITBASH. Every time l try to run the code l get a syntax error, need help om how to fix this. below is the code.

Find the even multiples of any number chosen by the user in a given range – the user
should specify the multiples of which number they want to print and a minimum and maximum
value. The multiples printed should be within the [minimum, maximum] range. For example, if
the user choses the number 7 and would like to print all even multiples in the [15, 60] range, the
program should print all the even multiples that are bigger than or equal to 15 (minimum), but
smaller than or equal to 60 (maximum). The program should keep a count of how many numbers
were printed and should output that count, as well as the numbers. The output then, for the
example given, should be 28, 42, 56, and the count should be 3. 

 

#.sh code
echo "Enter the number to find multiples:"
read num
echo  "Enter the minimum and maximum range of values to display: "
read min max
echo
count=0 #initialize index to 0
for (( i=$min; i <= $max; i+=2 ))

do

echo result[$count]=$i # If the i value is divisible by the number given and i is even then i is stored in result array
((count++)) #Increment count value by 1

((i++)) #increment i value by 1

echo "Multiples in given range[$min,$max] : ${result[@]}" #Display the Multiples in the given range

echo "Count of multiples is $count" #Display the count of multiples in the given range
done

 

Expert Solution
steps

Step by step

Solved in 2 steps

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