Adding two reals in shell

Solved
Hello,

I want to add two real numbers in a shell script. I've tried doing it in several ways, but none have produced a good result.

The only command that seems to work partially is the following:

addition='echo $var1 + $var2 | bc -l'


It displays the result with an error:

script.sh: line 40: 1.560: command not found 


Knowing that 1.560 is the expected result.

What do you think?

Configuration: Mac OS X / Safari 533.19.4

--
A dream leads to nothing, action leads to everything.
(J. FIAUX).

4 answers

  1. Hello,

    I use bash, and to add $var1 to $var2 and store the result in $addition, I would use this line:

    let addition=$var1+$var2

    but I might be wrong :p
    0
    1. Contributor
      Hi,

      Unfortunately, this method only applies to whole numbers ;-((
      0