0

I have to write a script with the bc command, and in doing so I am supposed to exit the bc without any input from the user. So basically the program will still run after the bc is used without waiting for input from the user like my program is currently doin. Here is the code:

cd /class/cm325d/06/dASG5

egrep 'James|Biel|Singlof|Hall|Lele|Kanter|Helms|Sahara|Jerrod|Dixon' asg5f1 > asg5f1c
sed 's/ /:/g' asg5f1c > t1
sed 's/$/:/g' t1 > asg5f1c
sort asg5f1c > t2
sort asg5f2 > t3
join t2 t3 > asg51
cut -d':' -f6 asg51 > gp
cut -d':' -f7 asg51 > np
sed 's/^/z=z+/' gp > gpay
sed 's/^/z=z+/' np > npay
echo "z" >> gpay
echo "z" >> npay
bc -q gpay > tgpay
bc -q npay > tnpay
exit
paste tgpay tnpay > totals

Obviously exit isn't working but I cannot figure out what to do I looked up online it says either quit or exit. I tried both and nothing. Any help would be appreciated. Thanks.

3 Answers 3

2

You can do just echo quit | bc -q gpay > tgpay, which will act almost like entering "quit" from the keyboard.

As another option, you may write bc < gpay > tgpay, which will pass the contents of gpay to stdin, running bc in non-interactive mode.

Sign up to request clarification or add additional context in comments.

2 Comments

I tried putting that code in it still waits for user input. I guess I should mention I am using ksh
Both constructions work with me in mksh (which is the closest shell to ksh I could install). However, it may depend on the contents of your files and the version of bc you are using.
1

"ctrl + d" should work. I'm able to terminate bc terminal with specified command.

Comments

-1

Press ctrl+d will work to exit the program.

you can also use Ctrl+c then use quit command

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.