I am trying to make a calculator with a bash script. The user enters a number, chooses whether they wish to add, subtract, multiply or divide. Then the user enters a second
This calculates uses up to 4 decimals (if needed), works without quotation marks.
calc ()
{
echo "scale=4;$*" | bc -l
}
Only downside is, you have to escape *
, else the shell will use it for file expansion.
Usage:
calc 1 + 2
calc 3 - 4
calc 44 \* 88
calc 77 / 234
This should do for most cases where you need a calculator fast.