Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.31 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. declare -i result=0
  4. declare -i i=0
  5. re='^[0-9]+$'
  6. while read line
  7. do
  8.     if ! [[ $line =~ $re ]] ; then
  9.         echo "error: Not a number" >&2
  10.         exit 0
  11.     else
  12.         let result=result+line
  13.         let i=i+1
  14.     fi
  15. done < "${1:-/dev/stdin}"
  16. echo $result
  17. echo $i
  18. bc -l <<< $result/$i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement