-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
90 lines (84 loc) · 2.23 KB
/
test.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
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
cd Data\
makeDatabase(){
if [ ! -f Database.txt ]; then
touch Database.txt
echo "Username || Password" >> Database.txt
else
echo "File Exists"
fi
}
makeLogs(){
if [ ! -f logs.log ]; then
touch logs.log
else
echo "File Exists"
fi
}
arrayRandom(){
lines=("1" "7" "13")
echo ${lines[@]}
echo ${!lines[@]}
rand=$((RANDOM%${#lines[@]}))
echo $rand
unset lines[$rand]
lines=("${lines[@]}")
echo ${lines[@]}
echo ${!lines[@]}
}
makeAnswer(){
if [ -f AnswerFile.txt ]; then
rm -rf AnswerFile.txt
touch AnswerFile.txt
else
touch AnswerFile.txt
fi
}
randomQuestion(){
question=1
lines=( 1 7 13 )
alines=(2 8 14)
blines=(3 9 15)
clines=(4 10 16)
dlines=(5 11 17)
i=0
makeAnswer
while [ $question -le 3 ]; do
timer=10
sec=$SECONDS
rand=$((RANDOM%${#lines[@]}))
current="${lines[$rand]}"
unset lines[$rand]
lines=("${lines[@]}")
seds=`sed -n "$current, $((current + 5))p" < QuestionBank.txt`
while [ $timer -gt 0 ]; do
clear
echo "Time Remaining: ${timer} Seconds"
echo
echo -n "$question. "
sed -n "$current, $((current + 5))p" < QuestionBank.txt
read -t 1 -n 1 answer && break
duration=$((10 - $sec))
(( timer-- ))
done
question=$(( question + 1 ))
echo $seds >> AnswerFile.txt
sed -i 's/\s\+\[\+/\n[/g' AnswerFile.txt
echo >> AnswerFile.txt
if [ $answer == "a" ]; then
sed -i "${alines[$i]}s/$/ -> You Answered this Question in $duration Seconds/" AnswerFile.txt
elif [ $answer == "b" ]; then
sed -i "${blines[$i]}s/$/ -> You Answered this Question in $duration Seconds/" AnswerFile.txt
elif [ $answer == "c" ]; then
sed -i "${clines[$i]}s/$/ -> You Answered this Question in $duration Seconds/" AnswerFile.txt
elif [ $answer == "d" ]; then
sed -i "${dlines[$i]}s/$/ -> You Answered this Question in $duration Seconds/" AnswerFile.txt
fi
(( i++ ))
done
}
makeDatabase
makeLogs
currentdate=$(date +"%Y-%m-%d %H:%M:%S")
echo $currentdate
arrayRandom
randomQuestion