Why does ...
sum=0; for i in 1 2 3 4; do echo "$i" | sum=$((sum+i)); done; echo $sum
... work as expected in zsh
but not in bash
? Perhaps because of bash not supporting floating point arithmetic? I also tried ...
sum=0; for i in 1 2 3 4; do echo "$i" | awk '{sum+=$1}'; done; echo $sum
... but that doesn't work in neither (this is on macOS 10.14.2). I found several related questions (such as this or this) but this question still remained.