LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (https://www.linuxquestions.org/questions/general-10/)
-   -   Linux elemental cli calculator bc. (https://www.linuxquestions.org/questions/general-10/linux-elemental-cli-calculator-bc-4175492732/)

stf92 01-27-2014 07:08 AM

Linux elemental cli calculator bc.
 
Hi: had it not a prompt. I type 'bc', immediately type operands and operators and get the result. No prompt?

rtmistler 01-27-2014 07:23 AM

Funny I never knew that existed. Pretty cool. Weird that it complains if you put in an equals. And you have to use -l if you do anything floating point.

Yeah, a prompt would be nice as well as allowing CTRL-C to just quit it. Looks like they put in a signal handler and they give you a statement. But who wants to "type" quit? Many also might look to type exit because that's what you use on an xterm.

druuna 01-27-2014 07:24 AM

Not entirely sure what you did, but bc doesn't have a visible prompt:
Code:

$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
 <-- no visible prompt here, just waiting for input

A complete session would look like this:
Code:

$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
3 + 4
7
quit
normal bash prompt


rtmistler 01-27-2014 08:04 AM

Took me a bit to locate it; I use google versus go right to GNU, where I eventually find it anyways. bc-1.06.tar.gz Modify the source to have a prompt, maybe make it give actual help versus return zero when you type help, IMHO allow equals, and by default, be able to perform floating point calculations. I'm not going to bother, it's cool but I usually have a desktop up, have plenty of actual calculators around too.

druuna 01-27-2014 08:23 AM

@rtmistler: some things can be done by invoking bc with the -l option.

Without -l:
Code:

$ bc -q
7/9
0

With -l:
Code:

$ bc -ql
7/9
.77777777777777777777

You can also put your default setting in a file and load it when using bc:
Code:

$ cat bcrc
scale=100
$ bc -q bcrc
7/9
.7777777777777777777777777777777777777777777777777777777777777777777\
777777777777777777777777777777777


stf92 01-27-2014 10:55 PM

Thank you guys. Then I was wrong. Yes, the blocking of ^C seems excess of tidiness.

TobiSGD 01-27-2014 11:15 PM

Quote:

Originally Posted by rtmistler (Post 5106066)
Yeah, a prompt would be nice as well as allowing CTRL-C to just quit it. Looks like they put in a signal handler and they give you a statement. But who wants to "type" quit? Many also might look to type exit because that's what you use on an xterm.

Just use Ctrl+d instead, works on the termianl also.


All times are GMT -5. The time now is 02:16 AM.