I am using the bc command in UNIX to parse some math expressions. I have two small functions:
function bashcalc {
echo $@ | bc -l
}
function2 {
...
catMinusMouse=$(bashcalc "$cat_angle - $mouse_angle")
cos=$(cosine $catMinusMouse)
val=$(bashcalc "$cat_radius * $cos") ##PARSE ERROR
...
}
When I tried to run the expression following val, I got quite a few "(standard_in) 1: parse error"s.
My first thought was that the asterisk was the issue so I tried escaping it. That however gave me an illegal character error.
The solution ended up being removing all of the whitespace
val=$(bashcalc "$cat_radius*$cos")
QUESTION: Why did calculating catMinusMouse (with spaces around the subtraction operator) work while the same format with multiplication did not work?