Is it possible to write a script that reads the file containing numbers (one per line) and writes their maximum, minimum and sum. If the file is empty, it will print an appropriate message. The name of the file is to be given as the parameter of the script. I mange to create below script, but there are 2 errors:
./4.3: line 20: syntax error near unexpected token `done' ./4.3: line 20: `done echo "Max: $max" '
Is it possible to add multiple files as parameter?
lines=`cat "$1" | wc -l` if [ $lines -eq 0 ]; then echo "File $1 is empty!" exit fi min=`cat "$1" | head -n 1` max=$min sum=0 while [ $lines -gt 0 ]; do num=`cat "$1" | tail -n $lines` if [ $num -gt $max ]; then max=$num elif [ $num -lt $min ]; then min=$num fiS sum=$[ $sum + $num] lines=$[ $lines - 1 ] done echo "Max: $max" echo "Min: number $min" echo "Sum: $sum"