#! /bin/sh
case $1 in
 -a)   if test $# -ne 4 
              then
                  echo correct usage tel -a  first last number
              else
                  grep "$2 $3" telephone >> tmp 
                  if [ $? -eq 0 ]
                  then
                      echo $2 $3 already exits
                  else
		      echo adding...
                      echo  $2 $3 $4 >> telephone
                  fi
       fi 
       ;;
  -d)  echo deleting...
       if test $2
       then
           grep -v $2 telephone > tmp$$
           cp tmp$$ telephone
           rm tmp$$
       else
           echo correct usage  tel -d entry
       fi
       ;;
  -f)  echo finding...
       if test $2
       then
           grep "$2" telephone
       else
           echo correct usage tel -f entry
       fi
       ;;
  -s)  echo sorting...
       sort telephone
       ;;
   *)  echo unrecognized option
       if test $1
       then
           grep "$1" telephone
       else
           cat telephone
       fi
       ;;
esac
echo done
