Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Console Calculator for Linux: bc

7 views
Skip to first unread message

Sidney Lambe

unread,
Oct 15, 2008, 5:34:14 PM10/15/08
to
For those of you who are running linux instead
of running kde, here's how to get a calculator
for the console that's simple as pie and can
do very complex stuff, too:

bc

It is already on your box in all likelihood.

Here's how to set it up. Put this in your system-wide
bash configuration file:

alias bc="bc -q"

(That just gets rid of a bunch of unnecessary
printed info about bc. q = quiet.)

export BC_ENV_ARGS=/etc/bc

Then create /etc/bc with just this in it:

scale=3

(That sets the number of digits to right of
the decimal point will that be displayed.)

Then do this in every console/xterm you are
running at the moment:

$ . <path to system-wide bash configuration file>

or

$ source <path to system-wide bash configuration file>

Using bc:

$ bc

Then

2 * 4 <enter> # to multiply
16 / 2 <enter> # to divide
10 - 5 <enter> # to substract
20 + 20 <enter># to add

last or . stands for the last printed number:

$bc
2 * 8
16
. / 2
8.000
last + 8
16.000

You can also do stuff like:

$bc
(10 + 10) / 5
4.000

To exit bc: Ctrl-d (^D).

links:

http://www.gnu.org/software/bc/manual/
http://en.wikipedia.org/wiki/Bc_programming_language

Source: http://ftp.gnu.org/pub/gnu/bc/bc-1.06.tar.gz

size 72K

Dependencies:

$ldd `which bc`
linux-gate.so.1 => (0xffffe000)
libreadline.so.5 => /usr/lib/libreadline.so.5 (0xb7f4c000)
libncurses.so.5 => /lib/libncurses.so.5 (0xb7f0b000)
libc.so.6 => /lib/libc.so.6 (0xb7dc9000)
libdl.so.2 => /lib/libdl.so.2 (0xb7dc5000)
/lib/ld-linux.so.2 (0xb7f84000)

All of which are on most linux boxes.


Sid


gnu/linux

unread,
Oct 15, 2008, 7:21:08 PM10/15/08
to
> http://www.gnu.org/software/bc/manual/http://en.wikipedia.org/wiki/Bc_programming_language

>
> Source:http://ftp.gnu.org/pub/gnu/bc/bc-1.06.tar.gz
>
> size 72K
>
> Dependencies:
>
> $ldd `which bc`
> linux-gate.so.1 => (0xffffe000)
> libreadline.so.5 => /usr/lib/libreadline.so.5 (0xb7f4c000)
> libncurses.so.5 => /lib/libncurses.so.5 (0xb7f0b000)
> libc.so.6 => /lib/libc.so.6 (0xb7dc9000)
> libdl.so.2 => /lib/libdl.so.2 (0xb7dc5000)
> /lib/ld-linux.so.2 (0xb7f84000)
>
> All of which are on most linux boxes.
>
> Sid

Thanks S.L. !

Beej Jorgensen

unread,
Oct 15, 2008, 10:04:50 PM10/15/08
to
Sidney Lambe <nos...@nospam.invalid> wrote:
>bc

I actually use this when I do my taxes. :)

Also consider starting it with the -l switch which defines a bunch of
math functions (trig, logs, and stuff).

-Beej

Sidney Lambe

unread,
Oct 15, 2008, 10:14:22 PM10/15/08
to
Beej Jorgensen <be...@beej.us> wrote:
> Sidney Lambe <nos...@nospam.invalid> wrote:
>>bc
>
> I actually use this when I do my taxes. :)

That's _serious_ math!

I know that bc can do it but just use it as a basic
calculator here.

>
> Also consider starting it with the -l switch which defines a bunch of
> math functions (trig, logs, and stuff).

Okay. I've considered it.

:-)


>
> -Beej
>

Thanks,

Sid


Ron AF Greve

unread,
Oct 17, 2008, 6:01:24 PM10/17/08
to


"Sidney Lambe" <nos...@nospam.invalid> wrote in message
news:m74is5x...@amma.net...

Although RPN fanatics would probably prefer dc the desktop calculator
ronafgreve@informationsuperhighway:~$ dc
2 4 *
p
8
16 2 /
p
8
q

:-)

> last or . stands for the last printed number:
>
> $bc
> 2 * 8
> 16
> . / 2
> 8.000
> last + 8
> 16.000
>
> You can also do stuff like:
>
> $bc
> (10 + 10) / 5
> 4.000
>
> To exit bc: Ctrl-d (^D).
>
> links:
>
> http://www.gnu.org/software/bc/manual/
> http://en.wikipedia.org/wiki/Bc_programming_language
>
> Source: http://ftp.gnu.org/pub/gnu/bc/bc-1.06.tar.gz
>

>.....
> Sid
>
>
Thanks.

Regards, Ron AF Greve


Sidney Lambe

unread,
Oct 17, 2008, 6:57:53 PM10/17/08
to

ROTFL! Now _there's_ a utility guaranteed to give you
a headache. It's worse than ed!

>
>> last or . stands for the last printed number:
>>
>> $bc
>> 2 * 8
>> 16
>> . / 2
>> 8.000
>> last + 8
>> 16.000
>>
>> You can also do stuff like:
>>
>> $bc
>> (10 + 10) / 5
>> 4.000
>>
>> To exit bc: Ctrl-d (^D).
>>
>> links:
>>
>> http://www.gnu.org/software/bc/manual/
>> http://en.wikipedia.org/wiki/Bc_programming_language
>>
>> Source: http://ftp.gnu.org/pub/gnu/bc/bc-1.06.tar.gz
>>
>>.....
>> Sid
>>
>>
> Thanks.
>
> Regards, Ron AF Greve
>
>

Cheers,

Sid

Beej Jorgensen

unread,
Oct 20, 2008, 1:33:13 AM10/20/08
to
Sidney Lambe <nos...@nospam.invalid> wrote:
>bc

One more thing along these lines that might be installed on your Linux
box is the vi of spreadsheets:

sc

Start it up and hit '?' for help.

-Beej

Sidney Lambe

unread,
Oct 20, 2008, 2:39:18 AM10/20/08
to
Beej Jorgensen <be...@beej.us> wrote:

You know, Mr. Beej, I have no idea how to use a
spreadsheet, which I believe to be a kind of database.
I can easily install it from the slackware cd, but
wouldn't know what to do with it.

I don't want to seem to be provincial, but can't in
good faith recommend an application that I don't know
a damn thing about and apparently have no use for.

Want to hear the bulk of a fine interview:

Lauren Weinstein
(http://www.vortex.com/)

It's about the future of the Internet.

He's on coasttocoastam (.com) right now. Here's where
to find the radio station carrying it nearest you:

http://www.coasttocoastam.com/info/wheretolisten.html

Sid

--
contact: http://tinyurl.com/5jxzoj
googlegroups users see:
http://tinyurl.com/5mbs7c

0 new messages