topical media & game development

talk show tell print

basic-shell-app-a-exercise-11-02.sh / sh



  #!/bin/sh
  
  # Using bc for math,
  # calculates sales tax.
  
  echo -n "Please enter the amount of purchase: "
  read amount
  echo
  
  echo -n "Please enter the total sales tax rate: "
  read rate
  echo 
  
  result=$( echo "
  scale=2; tax=amount*rate/100.00;total=amount+tax;print total" | bc )
  
  if [ $( expr "result > 200" ) ]
  then
      echo You could qualify for a special free shipping rate.
      echo -n Do you want to? "(yes or no) "
      read shipping_response
      if [ shipping_response -eq "yes" ]
      then
          echo "Free shipping selected."
      fi
  fi
  
  echo "The total with sales tax = $ result."
  echo "Thank you for shopping with the Bourne Shell."
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.