-
Notifications
You must be signed in to change notification settings - Fork 0
/
day1.sh
executable file
·49 lines (43 loc) · 1.06 KB
/
day1.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
function main {
date=`date +"%d/%m/%Y" `
echo "hello, i'm first exercise, today is $date and my master is Yoda"
echo -e "how many people are there?"
read -r people
echo "siamo $people"
count="0"
names=()
ages=()
while [ "$people" -gt "$count" ]
do
echo -e "enter your name :"
read -r name
names+=("$name")
echo "age"
read -r age
ages+=($age)
count=$(( $count + 1 ))
done
clear
echo '#################################################################'
echo -e "we are in total $people people\n"
count="0"
while [ "$people" -gt "$count" ]
do
echo -e "i'm `echo ${names[$count]}` and i'm ${ages[$count]} years old\n"
count=$(( $count + 1 ))
done
count="0"
agesum="0"
while [ "$people" -gt "$count" ]
do
agesum=$(( $agesum + ${ages[$count]} ))
count=$(( $count + 1 ))
done
echo -e "The sum of our ages is $agesum\n"
echo -e "Our names are ${names[@]}\n"
echo '#################################################################'
}
main
echo "Do you want to try again? [y/n]"
read -r ans ; echo $ans ; if [ $ans == "y" ] ; then clear ; main ; else exit ; fi