answersLogoWhite

0

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

Still curious? Ask our experts.

Chat with our AI personalities

MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
JudyJudy
Simplicity is my specialty.
Chat with Judy
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran

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