Domanda

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

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top