arahman22

addsubtract

Feb 22nd, 2012
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.53 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. typeset -i total=0
  4.  
  5. #typeset -i LINE
  6.  
  7. LINE=0
  8.  
  9.  
  10.  
  11.  
  12. while read operator LINE ; do
  13.  
  14. echo $operator ::: $LINE
  15. param2=`( echo $LINE | tr -d '[:alpha:]' )`
  16.  
  17. echo $param2, ${#param2}
  18.  
  19.  
  20.  
  21. if [[ ${#param2} -eq 0 ]] ; then
  22.  
  23.     echo $0: error
  24.  
  25.     exit 3
  26.  
  27. else
  28.    
  29. if [ $operator='+' ] ; then
  30.  
  31.         echo '+'  $operator
  32.  
  33.         total=total+$param2
  34.  
  35.         echo $total
  36.  
  37.     elif [ $operator='-' ] ; then
  38.  
  39.         echo $operator
  40.  
  41.         total=total-$param2
  42.  
  43.         echo $total
  44.  
  45.     else
  46.  
  47.         echo error
  48.  
  49.         exit 2
  50.  
  51.     fi
  52.  
  53. fi ; done
  54.  
  55.  
  56. echo total: $total
  57.  
  58.  
  59. exit 0
Advertisement
Add Comment
Please, Sign In to add comment