0

I'm a new user that is trying to learn bash, so I'm sorry if my code really bad or "stupid" because I learn bash from free pdf only. My question is: I have a file called "number" that's simply contains

1 3 4 2 9

I want to read it and sum them all together, however my code doesn't work. What I have so far is:

line=$(head -n 1 number)
echo "line"
while read $line
do
  sum=`expr $sum + $line`
  echo sum
done

Can someone help me to show the correct code? Also, when I call $line is it "1 3 4 2 9" or they split already become "1" "3" "4" "2" "9"?

Thank you.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
coava
  • 79
  • 3
  • 9
  • 1
    What must be another student in your class asked about this just a few hours ago: http://stackoverflow.com/questions/32917920/bash-find-average-of-numbers-in-line/ – John1024 Oct 03 '15 at 06:21
  • Oh, I'm really sorry about that. I didn't know he/she asked a similar questions. Thank you for your help. – coava Oct 03 '15 at 06:56

0 Answers0