-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhey.sh
executable file
·47 lines (41 loc) · 1.1 KB
/
hey.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
#!/bin/bash
# Lyric checking function
function lyric {
echo -e "\e[1m$1\e[0m"
echo -n "[Your response]: "
read response
if [[ $response != $2 ]];
then
echo -e "\nClearly you have not heard this new song. It's called"
figlet "$songtitle"
exit 2
fi
}
# Initial prompt for song name
echo -n "Hey, have you heard this new song? It's called: "
read songtitle
# Convert song name to filename
filename="$(echo $songtitle | sed -r 's/ /_/g').txt"
absolutepath="$(dirname "$0" | rev | cut -d "/" -f1- | rev)"
absolutepath="$absolutepath/Lyrics/$filename"
if [ ! -f $absolutepath ];
then
echo "Clearly you have not heard this new song."
exit 1
fi
echo -e "\n\e[1m\e[4m$songtitle\e[0m"
# Read in file two lines at a time and store in two arrays
# @kevingeng yes I know this is inefficient but I don't know how to code so fight me
lines=()
corrects=()
while read -r line; read -r correct
do
lines+=("$line")
corrects+=("$correct")
done < "$absolutepath"
# Use lines to lyric test
for ((i=0; i<=${#lines[@]}; i++)); do
lyric "${lines[i]}" "${corrects[i]}"
done
# Passed
echo -e "\nI guess you have heard this new song."