26 lines
603 B
Bash
26 lines
603 B
Bash
#!bin/bash
|
|
|
|
if [ $# -ne 6 ]; then
|
|
echo "Please provide 6 arguments"
|
|
exit 1
|
|
fi
|
|
|
|
total=0
|
|
count=0
|
|
|
|
marks=("$@")
|
|
# Expands the list of arguments to be space seperated, then splits the output
|
|
# on a space with a newline. The list is then sorted in descending order.
|
|
# This allows the iteration through the list until count = length=1, removing
|
|
# the last value from the calculation.
|
|
marks=($(echo "${marks[@]}" | tr ' ' '\n' | sort -nr))
|
|
|
|
while [ "$count" -lt 5 ]; do
|
|
total=$((total + marks[count]))
|
|
count=$((count + 1))
|
|
done
|
|
|
|
avg=$(( ( total + 5 / 2 ) / 5 ))
|
|
|
|
echo "Average of best five modules: $avg%"
|