#!/bin/ksh

typeset -i grand_total=0
typeset -i total1=0
typeset -i total2=0
typeset -i total3=0
typeset -i lines=0
typeset -i number

if test ! -r "benchdata.txt" ; then
   echo "benchdata.txt inaccessible"
   exit
fi
{ while read number ; do
  if [ $number = 1 ] ; then
     let "total1=total1+1"
  elif [ $number = 2 ] ; then
     let "total2=total2+1"
  elif [ $number = 3 ] ; then
     let "total3=total3+1"
  else
     echo "Unexpected value" >&2
  fi
  let "grand_total=grand_total+number"
  let "lines=lines+1"
  done
} < "benchdata.txt"

  echo "Number of values: \c"
  echo "$lines\c"
  echo
  echo "Total of 1s is: \c"
  echo "$total1\c"
  echo
  echo "Total of 2s is: \c"
  echo "$total2\c"
  echo
  echo "Total of 3s is: \c"
  echo "$total3\c"
  echo
  echo "Mean for the numbers is \c"
  echo "$((grand_total/lines))\c"
  echo
