Cannot sum numbers received from stdin using bc

And this works too: echo '(2.1+2.1)/2' | bc -l

Ah, but did you try:

echo '(2.1+2.1)/2' | tr -d '\n' | bc -l
(standard_in) 1: syntax error

Using echo -n will accomplish the same thing -- there's no terminating newline, and that's your problem.


bc has some pretty particular syntax. dc is less choosy:

find . -type f -exec entropy \{\} + |
sed 's/.*://;N;N;s/\n[^:]*:/+/g;s/+//;s|$| 3/p|' |
dc

I think that does what you're trying to do, but I'm not totally certain. An output sample larger than a single line would help.

Tags:

Shell

Bash

Bc