From 2129be264a26a677acd9bfce4a9e771c0021b3f3 Mon Sep 17 00:00:00 2001 From: Arkadiusz Hypki Date: Mon, 15 May 2023 16:58:59 +0200 Subject: [PATCH] ex1.sh changed to make a statistics for all countries at once - it prints everything at the end --- tabledata/ex1.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tabledata/ex1.sh b/tabledata/ex1.sh index 9d8d693..fb96f9f 100755 --- a/tabledata/ex1.sh +++ b/tabledata/ex1.sh @@ -6,13 +6,12 @@ echo "Podaj nazwę pliku z bazą danych" read inPlikWej -echo "Podaj kraj, który wyszukać" -read inKraj echo "Podaj minimalny wiek" read inWiek w=0 -sz=0 + +declare -A kraje # iterating line-by-line while read line @@ -27,9 +26,9 @@ then w=$((w + 1)) -if [ $country = "$inKraj" -a $age -ge $inWiek ] +if [ $age -ge $inWiek ] then - sz=$((sz + 1)) + kraje["$country"]=$((kraje["$country"] + 1)) echo "Person $name (from $country) is $age years old" fi @@ -37,4 +36,4 @@ fi done < $inPlikWej -echo "There is statistically `echo "scale=2; $sz/$w*100.0" | bc -l` % of such persons" +for key in ${!kraje[@]}; do echo "From $key there is ${kraje["$key"]} persons"; done