I can usually type faster in the terminal than doing mouse click on a gui calculator, so I created this scipt to be able to do it quickly from the terminal. There are alot of command line calculators out there so use the one you are comfortable with but I like using bc because of the syntax. For example, you can type:
calc "6/(3*10)"
or something more complex:
calc "8^2*(10/2+(13.2032565*2030)/.349548)" 100
100 is optional, it will specify how many decimals you want to carry it out to (the default is 4).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Command line calculator | |
# Display usage if no parameters given | |
if [ -z "$@" ]; then | |
echo " ${0##*/} <input> <*decimals> - command line calculator (-h for examples)" | |
exit | |
fi | |
# Decimal to be carried out to (uses four unless value is given) | |
if [ -z "$2" ]; then | |
decimals=4; else | |
decimals=$2 | |
fi | |
case $1 in | |
-h | --help ) echo " Requires quotes. Examples:" | |
echo ' calc "5*((2^3*2)/1.352)"' | |
echo ' calc "p=10; n=9; p*n+10"' ;; | |
* ) echo "scale=$decimals;$1" | bc | |
esac |
Try clac. I think you will find it far more powerful
I’m going to link to this post on my blog, I’ve been looking for a decent command line calculator to review and this looks great