answersLogoWhite

0


Best Answer

try a for loop:

for x in 1 2 3 4

n=0

do

n=`echo $x+$n`|bc

done

Integer arithmetic can be done in the shell itself without requiring an external program, making the operation much faster:

n1=123

n2=543

sum=$(( $n1 + $n2 ))

echo "$sum"

User Avatar

Wiki User

βˆ™ 13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you sum numbers in a Unix shell script?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Shell script to find out the sum of first 10 natural numbers?

Yes


In Shell script. How do I ask for and accept two numbers and then calculate the sum of the supplied numbers and display the sum.?

It depends on the script language you are using. In the Korn shell, you can say: echo -n "Enter the first number: " read first echo -n "Enter the second number: " read second let third=$first+$second echo The answer is $third


Write a program to calculate the sum of two numbers in unix?

$vi sum.sh echo "enter the 1st no." read num1 echo "enter the 2nd no." read num2 sum= 'expr $num1 + $num2' echo "sum of the numbers is $sum"


Unix program for adding of two numbers?

$vi sum.sh echo "enter the 1st no." read num1 echo "enter the 2nd no." read num2 sum= 'expr $num1 + $num2' echo "sum of the numbers is $sum"


Sum of n numbers in shell programming?

2 4 6


Shell program to find the sum of cube of individual digits of a number?

Shell problems are programs that can be run to find out information about numbers. The problem can help find an even or odd number, or what the sum of a cube is.


Javascript program for palindrome of numbers?

<html> <head><title>Check palindrim or not</title> <script language="javascript"> var no,rem,sum=0,temp; no=prompt("Enter the no from user for check"," "); temp=no; while(no>0) { rem=no%10; sum=sum*10+rem; no=no/10; } if(temp==sum) document.write("The given no is palindrom"); else document.write("The given no is not palindrom") </script> <body> </body> </html>


What does it mean answer to a sum?

To add the numbers together is the sum!!!! to add the numbers together is the sum!!!!


What is a sum in numbers?

Sum means to add numbers together.


What are the sum of two numbers if the sum of two consecutive even numbers is 26?

The sum of the numbers is 26. The numbers are 12 and 14.


From zero to 16 is all the odd numbers the sum of even numbers?

If this question means "in the interval 0 to 16 inclusive, is the sum of the odd numbers the same as the sum of the even numbers ?" then the answer is no. The sum of the even numbers is eight more than the sum of the odd ones.


Is sum of odd numbers always even?

The sum of two odd numbers is always even; the sum of three odd numbers is always odd; the sum of four odd numbers is always even; the sum of five odd numbers is always odd; etc