0

In shell script a command output gives integer number like :

xxx$> xxxx
10
20
30

I want to add those integer values and get sum value. What is the simplest way to do..?

zakinster
  • 10,508
  • 1
  • 41
  • 52

1 Answers1

4

Supposing your script is named xxxx, you could do :

xxxx | awk '{sum+=$1} END {print sum}'

Which would print the sum of the integers printed by xxxx :

~$ xxxx
10
20
30
~$ xxxx | awk '{s+=$1} END {print s}'
60
zakinster
  • 10,508
  • 1
  • 41
  • 52