Task

Compute the sum and product of an array of integers.




prod() {
   (read B; res=$1; test -n "$B" && expr $res \* $B || echo $res)
}
 
sum() {
   (read B; res=$1; test -n "$B" && expr $res + $B || echo $res)
}
 
fold() {
   (func=$1; while read a ; do fold $func | $func $a ; done)
}
 
 
(echo 3; echo 1; echo 4;echo 1;echo 5;echo 9) |
  tee >(fold sum) >(fold prod) > /dev/null