문제

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