forked from GGC-SD/bash_basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07-beer.sh
More file actions
92 lines (78 loc) · 2.12 KB
/
07-beer.sh
File metadata and controls
92 lines (78 loc) · 2.12 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh
echo "Let's sing a beer song"
echo "How many bottles?"
read count
while [ $count -ge 0 ]; do
if [ $count -ge 2 ]; then
echo "$count bottles of beer on the wall, $count bottles of beer"
echo "Take one down pass it around"
elif [ $count -eq 1 ]; then
echo "$count bottle of beer on the wall, $count bottles of beer"
echo "Take one down pass it around"
else
echo "no more bottles of beer on the wall"
fi
# the following statement is equivalent to: let "count=count-1"
((count = count - 1))
done
# exercise: implement another counting song (such as 12 days of Christmas)
# using loops and if statements.
echo "How many days, should we sing about?"
read day
current=$day
while [ $current -ge 1 ]; do
echo "On the $current day of our celebration, we enjoyed: "
if [ $current -ge 12 ]; then
echo " - Twelve lanterns glowing"
fi
if [ $current -ge 11 ]; then
echo " - Eleven crystals shining"
fi
if [ $current -ge 10 ]; then
echo " - Ten banners waving"
fi
if [ $current -ge 9 ]; then
echo " - Nine bells ringing"
fi
if [ $current -ge 8 ]; then
echo " - Eight stars a‑twinkling"
fi
if [ $current -ge 7 ]; then
echo " - Seven candles burning"
fi
if [ $current -ge 6 ]; then
echo " - Six ribbons fluttering"
fi
if [ $current -ge 5 ]; then
echo " - Five golden stones"
fi
if [ $current -ge 4 ]; then
echo " - Four silver charms"
fi
if [ $current -ge 3 ]; then
echo " - Three bright feathers"
fi
if [ $current -ge 2 ]; then
echo " - Two wooden carvings"
fi
echo " - One shining star"
echo ""
((current = current - 1))
done
echo "Now we sing about monkeys jumping on the bed"
echo "How many monkeys?"
read count
while [ $count -ge 0 ]; do
if [ $count -ge 2 ]; then
echo "$count little monkeys jumping on the bed"
echo "one fell off and bumped his head"
echo "Moma called the doctor and the doctor said"
echo "No more monkeys jumping on the bed!"
else
echo "$count little monkey jumping on the bed"
echo "He fell off and bumped his head"
echo "Moma called the doctor and the doctor said"
echo "No more monkeys jumping on the bed!"
fi
((count = count - 1))
done