user949814
user949814

Reputation:

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 bash.

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?

Upvotes: 3

Views: 3623

Answers (1)

entitledX
entitledX

Reputation: 680

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`

Upvotes: 3

Related Questions