#!/bin/bash

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

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

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