CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download
Views: 17
Image: ubuntu2204
1
!/bin/bash
2
# =============================================================
3
# Final project menu option
4
# VG
5
# 12/5/2023
6
# Menu is created for user to select an option from 1-6
7
# ./finalproject.sh
8
# ============================================================
9
while true; do
10
echo ' Menu'
11
echo '1. Display current date and time'
12
echo '2. Display the first letter of your first name'
13
echo '3. Display the line from the 'Twelve Days of Christmas' song'
14
echo '4. Sum of the two integers in your age'
15
echo '5. Random'
16
echo '6. Exit'
17
18
read -p 'Pick a selection from the menu (1-6): ' choice
19
20
21
if [ $choice -eq 6 ];
22
then break
23
24
25
elif [ $choice -eq 1 ]; then
26
datenow()
27
{
28
echo "Today's date and time are: "
29
date
30
}
31
datenow
32
33
34
35
elif [ $choice -eq 3 ]; then
36
37
38
39
read -p 'Pick number 1-12: ' choice2
40
if [ $choice2 -eq 1 ]; then
41
echo 'A partidge in a pear tree'
42
elif [ $choice2 -eq 2 ]; then
43
echo 'two turtle doves'
44
elif [ $choice2 -eq 3 ]; then
45
echo 'Three French hens'
46
elif [ $choice2 -eq 4 ]; then
47
echo 'Four calling birds'
48
elif [ $choice2 -eq 5 ]; then
49
echo 'Five gold rings'
50
elif [ $choice2 -eq 6 ]; then
51
echo 'Six geese a-laying'
52
elif [ $choice2 -eq 7 ]; then
53
echo 'Seven swans a-swimming'
54
elif [ $choice2 -eq 8 ]; then
55
echo 'Eight maids a-milking'
56
elif [ $choice2 -eq 9 ]; then
57
echo 'Nine ladies dancing'
58
elif [ $choice2 -eq 10 ]; then
59
echo 'Ten lords a-leaping'
60
elif [ $choice2 -eq 11 ]; then
61
echo 'Eleven pipers piping'
62
elif [ $choice2 -eq 12 ]; then
63
echo 'Twelve drummers drumming'
64
else
65
echo 'Invalid number input. Please a number between 1 and 12.'
66
67
fi
68
69
70
71
elif [ $choice -eq 4 ]; then
72
read -p 'Sum of your two digits in your age (two digits): ' age
73
if [[ $age =~ ^[0-9][0-9]$ ]]; then
74
digit1=$(echo $age | cut -c 1)
75
digit2=$(echo $age | cut -c 2)
76
sum=$((digit1 + digit2))
77
echo 'The sum of the two numbers in your age is: ' $sum
78
else
79
echo 'Please enter a number that is two digits.'
80
81
fi
82
83
elif [ $choice -eq 2 ]; then
84
85
read -p "Enter your first name and the first letter will be returned: " name
86
name=$(echo "$name" | tr -d ' ')
87
echo "The first letter of your first name is: ${name:0:1}"
88
89
90
91
92
elif [ $choice -eq 5 ]; then
93
echo "What is your favorite car?"
94
read -p "Please enter your favorite car: " favCar
95
echo "Very cool, $favCar is a great car."
96
97
98
fi
99
100
101
done
102
103