Command line expression solver?
bc & dc
bc
and dc
are the 2 calculators that I'll often use when needing access from a terminal.
Examples
$ 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:
2
2
5+5
10
When you're done you can get out with a Ctrl+C.
Test drive
These calculators are pretty feature rich.
scaling
scale=5
193 * 1/3
64.33333
equations
principal=100
ir = 0.05
years = 5
futurevalue = principal * (1 + ir)^years
futurevalue
127.62800
your examples
8*6-4
44
8*(6-4)
16
calc
If you want something a little more interactive there's calc
.
Example
$ calc
C-style arbitrary precision calculator (version 2.12.4.4)
Calc is open software. For license details type: help copyright
[Type "exit" to exit, or "help" for help.]
; 10+10
20
; 8*6-4
44
; 8*(6-4)
16
;
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
...
References
calc
's main reference pagecalc
's man page
There are many answers to your question...
The simple ones you could do in the shell.
$ echo $((8*(6-4)))
16
As a dedicated program there is bc
.
$ echo "8*(6-4)" | bc
16
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)
16.0
In zsh
:
$ autoload zcalc # best in ~/.zshrc
$ zcalc
1> 8*(6-4)
16
2> $1*2
32