Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions 07-beer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,38 @@ done

# exercise: implement another counting song (such as 12 days of Christmas)
# using loops and if statements.

echo "Let's sing a Christmass song!"

days=1
while [ $days -le 12 ]; do
if [ $days -eq 1 ]; then
echo "On the first day of Christmas, my true love sent to me... A partridge in a pear tree"
elif [ $days -eq 2 ]; then
echo "On the second day of Christmas, my true love sent to me... Two turtle doves and A partridge in a pear tree"
elif [ $days -eq 3 ]; then
echo "On the third day of Christmas, my true love sent to me... Three french hens Two turtle doves and A partridge in a pear tree"
elif [ $days -eq 4 ]; then
echo "On the fourth day of Christmas, my true love sent to me: four calling birds, three French hens, two turtle doves, and a partridge in a pear tree"
elif [ $days -eq 5 ]; then
echo "On the fifth day of Christmas, my true love sent to me: five golden rings, four calling birds, three French hens, two turtle doves, and a partridge in a pear tree."
elif [ $days -eq 6 ]; then
echo "On the sixth day of Christmas, my true love sent to me: six geese a-laying, five golden rings, four calling birds, three French hens, two turtle doves, and a partridge in a pear tree."
elif [ $days -eq 7 ]; then
echo "On the seventh day of Christmas, my true love sent to me: seven swans a-swimming, six geese a-laying, five golden rings, four calling birds, three French hens, two turtle doves, and a partridge in a pear tree."
elif [ $days -eq 8 ]; then
echo "On the eighth day of Christmas, my true love sent to me: eight maids a-milking, seven swans a-swimming, six geese a-laying, five golden rings, four calling birds, three French hens, two turtle doves, and a partridge in a pear tree."
elif [ $days -eq 9 ]; then
echo "On the ninth day of Christmas, my true love sent to me: nine ladies dancing, eight maids a-milking, seven swans a-swimming, six geese a-laying, five golden rings, four calling birds, three French hens, two turtle doves, and a partridge in a pear tree."
elif [ $days -eq 10 ]; then
echo "On the tenth day of Christmas, my true love sent to me: ten lords a-leaping, nine ladies dancing, eight maids a-milking, seven swans a-swimming, six geese a-laying, five golden rings, four calling birds, three French hens, two turtle doves, and a partridge in a pear tree."
elif [ $days -eq 11 ]; then
echo "On the eleventh day of Christmas, my true love sent to me: eleven pipers piping, ten lords a-leaping, nine ladies dancing, eight ma"
else
echo "On the twelfth day of Christmas, my true love sent to me: twelve drummers drumming, eleven pipers piping, ten lords a-leaping, nine ladies dancing, eight maids a-milking, seven swans a-swimming, six geese a-laying, five gold rings, four calling birds, three French hens, two turtle doves, and a partridge in a pear tree."
fi

# the following statement is equivalent to: let "count=count-1"
((days = days + 1))

done
Binary file added 2Branches Caleb Butler.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Merged Caleb Butler.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.