开发者

Average of list of floating point numbers Bash

开发者 https://www.devze.com 2023-04-05 06:21 出处:网络
I am trying to find the average of a bunch of floating point numbers from a file using bc in b开发者_开发技巧ash.

I am trying to find the average of a bunch of floating point numbers from a file using bc in b开发者_开发技巧ash.

right now, when I add I use:

let "sum=sum+${NUMBERS[$i]} | bc"

` I get syntax errors when I do this however. Syntactically, what is wrong with this?


bc is expecting standard input. Since the first command has no standard output, bc has no input in this case. Try this:

sum=`echo $sum+${NUMBERS[$i]} | bc -l`
0

精彩评论

暂无评论...
验证码 换一张
取 消