简体   繁体   中英

using bc in bash script

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM