Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a Linux-compatible TTY-based calculator. For example:

user@host:~$ calculate
> 2
user@host:~$ calculate
> 8*6-4
user@host:~$ calculate
> 8*(6-4)

Is there anything like this that supports basic operations, some built-in functions like atan(), and possibly custom functions via scripting?

share|improve this question
up vote 7 down vote accepted

bc & dc

bc and dc are the 2 calculators that I'll often use when needing access from a terminal.


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

Then you can type your questions:


When you're done you can get out with a Ctrl+C.

Test drive

These calculators are pretty feature rich.


193 * 1/3


ir = 0.05
years = 5
futurevalue = principal * (1 + ir)^years


your examples




If you want something a little more interactive there's calc.


$ calc
C-style arbitrary precision calculator (version
Calc is open software. For license details type:  help copyright
[Type "exit" to exit, or "help" for help.]

; 10+10
; 8*6-4
; 8*(6-4)

You can use the up/down arrows to go through past commands and it also has interactive help.

; help

Gives you this:

For more information while running calc, type  help  followed by one of the
following topics:

    topic               description
    -----               -----------
    intro               introduction to calc
    overview            overview of calc
    help                this file

    assoc               using associations
    builtin             builtin functions
    command             top level commands
    config              configuration parameters
    custom              information about the custom builtin interface
    define              how to define functions
    environment         how environment variables effect calc
    errorcodes          calc generated error codes
    expression          expression sequences
    file                using files
    history             command history
    interrupt           how interrupts are handled
    list                using lists
    mat                 using matrices

See the man page for more info.

share|improve this answer

There are many answers to your question...

The simple ones you could do in the shell.

$ echo $((8*(6-4)))

As a dedicated program there is bc.

$ echo "8*(6-4)" | bc

Custom functions via scripting? Well, shell scripts and bc both have them, in a way. Depends on how far you want to take it.

Why not Python? It's easy to learn.

$ python
>>> from math import atan
>>> 8*(6-4)+atan(0)
share|improve this answer
I've actually been using Python for this lately, but that's the reason I want something else. It gets annoying having to import something for every function. I was hoping more for something self-contained, like Speedcrunch (i.imgur.com/Cn6GejG.png), but command line obviously. – Lucas Phillips Dec 14 '13 at 2:22
You can solve import problem by defining PYTHONSTARTUP environment variable and preimporting stuff in the file pointed to by the variable. – Ketan Dec 14 '13 at 3:20

In zsh:

$ autoload zcalc  # best in ~/.zshrc
$ zcalc
1> 8*(6-4)
2> $1*2
share|improve this answer

Maxima CAS :

   L(t):=exp(%i*t*2*%pi); /* unit circle parametrised with angle in turns */
   [plot_format, gnuplot],
   [gnuplot_out_file, "atan2.png"],
   [legend, "atan2"],
   [xlabel,"angle in radians"], 
   [ylabel,"angle in radians"],
   set key left top;
   set xtics ('pi/2' 0.25, 'pi' 0.5, '3pi/2' 0.75,'2pi' 1.0);
   set ytics ('-2pi' -6.283, '-pi' -3.1415, '-pi/2' -1.5708, '0' 0, 'pi/2'  1.5708, 'pi' 3.1415, '2pi' 6.283);
   set grid xtics ytics "]


share|improve this answer

Here's a little bash hack that will let you do simple arithmetic directly on the commandline.

alias calc='set -o noglob; docalc'
function docalc { perl -e "print STDOUT $*, \"\\n\""; set +o noglob; }

Then you can do, e.g.,

calc 3 * 15 + 5

Unfortunately it doesn't play well with parentheses. (If I recall correctly you can get tcsh to accept those too, but I couldn't persuade bash to.)

PS. You could rely on bash for the arithmetic, by replacing the perl call with echo $(( $* )); but that'll give you integer division for 5/6, etc. Perl's arithmetic is more useful.

Alternative: If your only beef with python is that you need to import math, the following is your friend:

% alias calc='python -i -c "from math import *"'
% calc
>>> 5 * atan(0.25)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.