开发者

Average of list of floating point numbers Bash

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜