-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfortune.sh
More file actions
executable file
·39 lines (34 loc) · 897 Bytes
/
fortune.sh
File metadata and controls
executable file
·39 lines (34 loc) · 897 Bytes
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
#!/bin/bash
# Program to tell a person’s fortune
# title
echo -e "\n~~ Fortune Teller ~~\n"
# Get a question from the user making sure it ends with a question mark
GET_FORTUNE () {
if [[ ! $1 ]]
then
echo Ask a yes or no question:
else
echo Try again. Make sure it ends with a question mark:
fi
read QUESTION
}
# Execute the function to get the question
GET_FORTUNE
# Loop until the question ends with a question mark
until [[ $QUESTION =~ \?$ ]]
do
GET_FORTUNE again
# Pass 'again' as an argument to the function so that $1 is not empty
done
RESPONSES=("Yes"
"No"
"Maybe"
"Without a doubt"
"Very doubtful"
"Outlook good"
"Most likely"
"Don't count on it"
"Ask again later"
"Cannot predict now")
N=$(( RANDOM % ${#RESPONSES[@]} ))
echo -e "\n${RESPONSES[$N]}"