title: A simple small shell script to compute averages
body: <p>Can anyone tell me what I'm doing wrong here?</p>
  
  <pre><code>#!/bin/sh
  
  if [ $# = 0 ]
  then
      echo "Usage: $0 &lt;filename&gt;"
      exit 1
  fi
  
  sum=0
  count=0
  
  while [ $0 != 0 ]
  do
          sum="$sum"+"$2"
          count="$count"+ 1
  
  done
  if [ "$count" != 0 ]
  then
          avg="$sum"/"$count"
          printf "Sum= $sum \n Count= $count  \n Avg= $avg"
          exit 0
  else
          printf "Sum= $sum \n Count= $count  \n Avg= undefined"
          exit 0
  fi
  exit 1
  </code></pre>
  
  <p>Here's the output when I try to test the code:</p>
  
  <pre><code>./average
  
  sum: =: No such file or directory
  sum: 0: No such file or directory
  ./average: 11: count: not found
  [: 18: !=0: unexpected operator
  ./average: 25: Syntax error: Unterminated quoted string
  </code></pre>
  
  <p>Basically if I had a file that looked something like this:</p>
  
  <pre><code>FirstPerson 23 
  
  SecondPerson 36
  
  ThirdPerson 22
  </code></pre>
  
  <p>I want to be able to read that into my program and have it output:  </p>
  
  <pre><code>Sum = FirstPerson+SecondPerson+ThirdPerson
  
  Count = NumberofPeople
  
  Average = Sum/Count
  </code></pre>