arahman22

addsubtract

Feb 22nd, 2012
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. typeset -i total=0
  3. #typeset -i LINE
  4. LINE=0
  5.  
  6.  
  7. while read operator LINE ; do
  8. echo $operator ::: $LINE
  9. param2=`( echo $LINE | tr -d '[:alpha:]' )`
  10. echo $param2, ${#param2}
  11.  
  12. if [[ ${#param2} -eq 0 ]] ; then
  13.     echo $0: error
  14.     exit 3
  15. else   
  16.     if [ $operator='+' ] ; then
  17.         echo '+'  $operator
  18.         total=total+$param2
  19.         echo $total
  20.     elif [ $operator='-' ] ; then
  21.         echo $operator
  22.         total=total-$param2
  23.         echo $total
  24.     else
  25.         echo error
  26.         exit 2
  27.     fi
  28. fi ; done
  29.  
  30. echo total: $total
  31. exit 0
Advertisement
Add Comment
Please, Sign In to add comment