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

有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top