Question: Write a bash script which when executed, expects two integers, say n1 and n2. If the first argument, n1, is greater than the second argument,

Write a bash script which when executed, expects two integers, say n1 and n2. If the first argument, n1, is greater than the second argument, n2, the script calls a function (written within the script) and passes to the function n1 and n2 to compute the sum from n1 to n2. This function returns the sum which the script prints. If n1 is not greater than n2, the script calls the same function and passes the n1 and n2 to compute the sum from n2 to n1, and the script prints the sum returned by the function. Below is the expected dialog or interface:

$ ./script9

ERROR: The script expects two arguments.

$ ./script9 3 6

The sum from 3 to 6 is 18.

$ ./script9 3 3

The sum from 3 to 3 is 3.

$ ./script9 6 3

The sum from 3 to 6 is 18.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!