Question

Create a bash script that takes numbers as parameters, calculates sum and prints the result. If...

Create a bash script that takes numbers as parameters, calculates sum and prints the result. If no parameters passed, prompt a user (only one time) to enter numbers to sum and print the result.

Homework Answers

Answer #1

sum=0
if [ $# -eq 0 ]
then
read -p "Enter first number: " num1
read -p "Enter second number: " num2
sum=$(( $num1 + $num2 ))
else
for i do
sum=$(expr $sum + $i)
done
fi
echo $sum

 

 
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a bash script that takes numbers as parameters, calculates sum and prints the result. If...
Create a bash script that takes numbers as parameters, calculates sum and prints the result. If no parameters passed, prompt a user (only one time) to enter numbers to sum and print the result.
Use BASH to run this, Make a code that takes any list of numbers and calculates...
Use BASH to run this, Make a code that takes any list of numbers and calculates and displays the mean, median and mode.
Bash script Suppose you are working as a prof or TA and your students have an...
Bash script Suppose you are working as a prof or TA and your students have an assignment which requires them each to hand in exactly one file. You've got a directory with all of the submitted files in it, and no other files. You're also lucky enough to have a script that will do all the work of marking a submission; it will take the name of a submission file as its only parameter and will print out a single...
In UNIX .Write a bash script that takes a list of usernames as its command line...
In UNIX .Write a bash script that takes a list of usernames as its command line arguments and displays on the screen, for each user name, a message of the form Number of times that logged into this machine is where is to be replaced by the number of recors that the last command output that match exactly. For example, if i enter command logincount mark it should output something like number of times that sweiss logged into this machin...
Create a simple addition calculator in Java. The program should prompt the user to enter 2...
Create a simple addition calculator in Java. The program should prompt the user to enter 2 integers, then adds the numbers and prints the result. Make sure the program includes appropriate exception handling in case the user does not enter appropriate integer values.
C++ Write a program that calculates and prints the total grade for n assignments as a...
C++ Write a program that calculates and prints the total grade for n assignments as a percentage. Prompt the user to enter the value of n, followed by the number of points received and number of points possible for each assignment . Calculate and print the total number of points received, total number of points possible, and the overall percentage: (total points received / total points possible) * 100. Output: Enter·number·of·assignments·to·input:3↵ Enter·number·of·points·received·for·assignment·1 :10↵ Enter·number·of·possible·points·for·assignment·1 :10↵ Enter·number·of·points·received·for·assignment·2 :7↵ Enter·number·of·possible·points·for·assignment·2 :12↵ Enter·number·of·points·received·for·assignment·3...
Create a python script that reads in an unknown number of positive numbers and negative numbers....
Create a python script that reads in an unknown number of positive numbers and negative numbers. These numbers are to be stored in two different collections. Once the user enters a zero value, the script will output all of the values in both collections, separately. Sample Usage/Output: Please enter a positive or negative number (enter a zero to end): 5 Please enter a positive or negative number (enter a zero to end): -7 Please enter a positive or negative number...
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them.         [0.5 mark] (BY USING C PROGRAM)
Define a recursive rangeSum(from, to) method that calculates and prints the sum of numbers between the...
Define a recursive rangeSum(from, to) method that calculates and prints the sum of numbers between the two values inclusive. IN JAVA. OUTPUT rangeSum(1,5) -> 15 rangeSum(1,5) -> 1+2+3+4+5=15 rangeSum(-3,4) -> 4 rangeSum(-3,4) -> -3+-2+-1+0+1+2+3+4=4 rangeSum(-5, 7) -> 13 rangeSum(-5, 7) -> -5+-4+-3+-2+-1+0+1+2+3=-9 please write main method as well as output for three above methods.
Use C++ Write a program that first reads in how many whole numbers the user wants...
Use C++ Write a program that first reads in how many whole numbers the user wants to sum, then reads in that many whole numbers, and finally outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the numbers just once each and the user can enter them...