4

I am trying outputing result in floating point using bc in bash.But I am getting the following output for the following code.How can i get the multiplication result from here and also why i am getting command not found.

 #!/bin/bash 
 v1=3.41 
 v2=45 
 v3= $(bc <<< "scale=4;$v1 + $v2")
 echo $v3 
 v3= $(bc <<< "scale=4;$v1 - $v2") 
 echo $v3 
 v3= $(bc <<< "scale=4;$v1 / $v2") 
 echo $v3 
 v3= $(bc <<< "scale=4;$v1 % $v2") 
 echo $v3
 v3 = $(bc <<< "scale=4;$v1 * $v2") 
 echo $v3 

the output i am getting is below :

mint@mint ~ $ bash bc.sh 
bc.sh: line 4: 48.41: command not found

bc.sh: line 6: -41.59: command not found

bc.sh: line 8: .0757: command not found

bc.sh: line 10: .0035: command not found

bc.sh: line 12: v3: command not found
user3708629
  • 153
  • 1
  • 1
  • 7

1 Answers1

6

Whitespace does matter. Remove it.

v3= $(bc <<< "scale=4;$v1 + $v2")
   ^

Explanation: The following command runs app with a locally exported var with a value value:

var=value app

In your case value is empty.

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176