[root@master yjt]# cat yjt.sh
#!/bin/bash
awk -v field="$1" '{sum+=$field; n++;}END {if (n > 0) print sum/n;else {print 'error' > "/tmp/.stderr"; exit 1};}' tt
[root@master yjt]# cat tt1 2 31 2 34 5 6