I am looking for a Calculator which can do calculations in the terminal itself without any other extra prefixes and suffixes.
For example: If I typed something like 10000-9000 in the terminal, the answer should come out as 1000.
Once again I am saying, I just need a quick calculator in terminal, without any characters added. I know if I switch to Python, it can do that but I don't want it in such a way.
Best Answer
Bash Arithmetic
Another possible solution is to add a simple function for Bash's builtin arithmetic. Put this in your
.bashrc
file to try:So now, you don't even need
$((...))
anymore, just=
which seems natural enough.Replacement
Another thing if you want to be even faster: you can make it replace
p
with+
andx
with*
. This will work for that:Now you don't even need Shift anymore, the only thing is
=
in front of arithmetic.Hexadecimal output
Output can be displayed in both decimal and hexadecimal, if so desired. (Note: using
x
substitution will conflict with the0x...
hex syntax)Example:
Using
bc
If you want slightly more advanced calculations, you can pipe it to
bc
like so:The functions provided by
bc
are as follows (and can be found fromman bc
):It also supports
if
,for
,while
and variables like a programming language though if it may be better to write to a file if you wanted that.Keep in mind that it will substitute
p
andx
in function/variable names. It may be better to just remove the replacements.Using
gcalccmd
You can also make the function call
gcalccmd
(fromgnome-calculator
) like so:The available functions seem to be (taken straight from the source code),
==
denotes equivalent functions: