Compare commits
3 Commits
d18ee6abe3
...
c477b99571
Author | SHA1 | Date | |
---|---|---|---|
|
c477b99571 | ||
|
924196de1f | ||
|
c0671db3bb |
18
2023.05.22_zajęcia_asynchroniczne/guess.sh
Executable file
18
2023.05.22_zajęcia_asynchroniczne/guess.sh
Executable file
@ -0,0 +1,18 @@
|
|||||||
|
echo "Guess game. What is the number I'm thinking about?"
|
||||||
|
|
||||||
|
num=$(($(($RANDOM % 20))+1))
|
||||||
|
|
||||||
|
ex=1
|
||||||
|
while [ 1 -eq $ex ]
|
||||||
|
do
|
||||||
|
read usr
|
||||||
|
|
||||||
|
if [ $num == $usr ]
|
||||||
|
then
|
||||||
|
echo "Great it is $num"
|
||||||
|
ex=0
|
||||||
|
else
|
||||||
|
echo "No, it is not that number"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
@ -8,12 +8,11 @@ echo "Podaj plik z danymi"
|
|||||||
read inPlik
|
read inPlik
|
||||||
echo "Podaj wiek"
|
echo "Podaj wiek"
|
||||||
read inWiek
|
read inWiek
|
||||||
echo "Podaj kraj"
|
|
||||||
read inKraj
|
|
||||||
|
|
||||||
ile=0
|
|
||||||
wszyscy=0
|
wszyscy=0
|
||||||
|
|
||||||
|
declare -A kraje
|
||||||
|
|
||||||
# iterating line-by-line
|
# iterating line-by-line
|
||||||
while read line
|
while read line
|
||||||
do
|
do
|
||||||
@ -27,9 +26,9 @@ then
|
|||||||
|
|
||||||
wszyscy=$((wszyscy+1))
|
wszyscy=$((wszyscy+1))
|
||||||
|
|
||||||
if [ $country = "$inKraj" -a $age -ge $inWiek ]
|
if [ $age -ge $inWiek ]
|
||||||
then
|
then
|
||||||
ile=$((ile+1))
|
kraje["$country"]=$((kraje["$country"]+1))
|
||||||
echo "Person $name (from $country) is $age years old"
|
echo "Person $name (from $country) is $age years old"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -38,4 +37,9 @@ fi
|
|||||||
done < $inPlik
|
done < $inPlik
|
||||||
|
|
||||||
#echo "There is $ile people from $inKraj (from all $wszyscy people)"
|
#echo "There is $ile people from $inKraj (from all $wszyscy people)"
|
||||||
echo "There is `echo "scale=2; $ile/$wszyscy*100.0" | bc -l`% people from $inKraj"
|
#echo "There is `echo "scale=2; $ile/$wszyscy*100.0" | bc -l`% people from $inKraj"
|
||||||
|
#echo "Num of people from Poland is ${kraje["Poland"]}"
|
||||||
|
#echo "Num of people from Germany is ${kraje["Germany"]}"
|
||||||
|
|
||||||
|
|
||||||
|
for key in ${!kraje[@]}; do echo "People from $key is `echo "scale=2; ${kraje["$key"]}/$wszyscy*100.0" | bc -l`%"; done
|
||||||
|
Loading…
Reference in New Issue
Block a user