Find the answer to your Linux question:
Results 1 to 3 of 3
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2012
    Location
    Pennsylvania
    Posts
    11

    bc within bash script.


    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.
    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

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    hi,

    you could just send a copy of your script's output to a file using tee, e.g.:

    Code:
    ./bc-script.sh|tee /tmp/bc-script.txt
    it's not pretty, but everything is there.
    Last edited by atreyu; 4 Weeks Ago at 12:25 AM. Reason: included link to tee

  3. #3
    Just Joined!
    Join Date
    Mar 2012
    Location
    Pennsylvania
    Posts
    11
    atreyu, I want to thank you for replying to my post. Your right it's not pretty. The tee command did make a ghost image of my scripts output to a file. What I was looking for was a way to just send the value of ti and tax to two separate files. So, that I could call them with another script.
    Code:
    echo "Enter past total earnings "; read pi < bctivalue
    If you come across the solution, please let me know. I want to thank you again for your help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •