bc within bash script.

  • Thread starter Thread starter heican
  • Start date Start date
H

heican

My question is how do I get the value of the variable ti and tax to a file? The script seems to work OK. But I don't know how to get the variable values to a file. Because the bc code is multiple lines I don't know if I could use the bash read command? Will be grateful for any help.:confused:
Code:
#!/bin/bash
clear
#These are these variables
echo "Enter past total earnings "; read pi
echo "Enter recent earnings "; read e
#This is the bc code
bc << EOS
scale=2
ti=$pi+$e
"This is your new total earnings $"; ti
define tab1() { tax=$e*.05 }
define tab1a() { tax=$e*.10 }
define tab2() { oe=ti-25000; ue=$e-oe; ea1=oe*.10; ua1=ue*.05; tax=ea1+ua1 }
define tab2a() { tax=$e*.15 }
define tab3() { oe=ti-50000; ue=$e-oe; ea1=oe*.15; ua1=ue*.10; tax=ea1+ua1 }
define tab3a() { tax=$e*.20 }
define tab4() { oe=ti-75000; ue=$e-oe; ea1=oe*.20; ua1=ue*.15; tax=ea1+ua1 }
if (ti < 25000) tab1()
if (ti >= 25000 && ti < 50000) if ($pi >= 25000) tab1a() else tab2()
if (ti >= 50000 && ti < 75000) if ($pi >= 50000) tab2a() else tab3()
if (ti >= 75000 && ti < 100000) if ($pi >= 75000) tab3a() else tab4()
if (ti >= 100000) tax=$e*.25
"$";tax
EOS

Continue reading...
 
Back
Top