Se eu estivesse implementando isso no bash, faria o seguinte. Não vou comentar muito: sinta-se à vontade para fazer perguntas específicas - verifique primeiro a página man do bash se você não souber como um comando em particular funciona.
#!/bin/bash
# read the population from all the files
# map the filename to it's population figure
declare -A population
while IFS= read -d '' -r filename; do
population["$filename"]=$(tail -1 "$filename")
done < <(find . -type f -print0)
# prompt the user for the year
read -rp "What year? " year
# find the relevant files for that year
year_files=()
for filename in "${!population[@]}"; do
[[ $filename == ./"$year"/* ]] && year_files+=("$filename")
done
if [[ "${#year_files[@]}" -eq 0 ]]; then
echo "No files for year '$year'"
exit 1
fi
PS3="Select a function to calculate: "
select func in minimum maximum average quit; do
case $func in
minimum)
min=${population[${year_files[0]}]}
for file in "${year_files[@]}"; do
if (( min > ${population[$file]} )); then
min=${population[$file]}
fi
done
echo "Minimum for $year is $min"
;;
maximum)
max=${population[${year_files[0]}]}
for file in "${year_files[@]}"; do
if (( max < ${population[$file]} )); then
max=${population[$file]}
fi
done
echo "Maximum for $year is $max"
;;
average)
count=0 sum=0
for file in "${year_files[@]}"; do
(( sum += ${population[$file]} ))
(( count++ ))
done
echo "Average for $year is $(( sum / count ))"
;;
quit) exit ;;
esac
done