Reputation: 111
I am trying to do some floating point maths in bash. I have been examining this thread, as well as many other sources of information: BASH Arithmetic Expressions
Just as an example, I am using:
c='echo "2\*4.2"|bc'
echo $c
but getting:
echo "2\*4.2"|bc
out.
I want just the value of the multiplication.
I have also tried:
$c='echo "2\*4.2"|bc'
echo $c
But then I get:
"2\*4.2"|bc=echo "2\*4.2"|bc
I'm quite confused, any suggestions?
Ciara
Upvotes: 2
Views: 271
Reputation: 195269
c=`echo "2*4.2"|bc`
echo $c
**Note the difference between quote ' and back tick `
or
c=$(echo "2*4.2"|bc)
echo $c
Upvotes: 3