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..?
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..?
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