#!/bin/bash len=0 total=0 while read -r num do len=$(( $len + 1 )) total=$(( $total + $num )) done < input.txt echo "length is $len and total is $total" avg=$(( $total / $len )) echo "Average is $avg"