Question

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

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top