-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquiz_test.sh
270 lines (231 loc) · 5.43 KB
/
quiz_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/bash
sign_up ()
{
header
echo -e "\e[92m<<<<<\e[0m Signup \e[92m>>>>>\e[0m"
users=(`cat user_name.csv`)
echo "Enter Username:"
read username
for user in `seq 0 $((${#users[@]}-1))`
do
userid=${users[$user]}
if [ $userid = $username ]
then
echo -e "\e[31mUsername already exists! Plase use different username.\e[0m"
sign_up
fi
done
pw=1
while [ $pw -ne 0 ]
do
echo "Enter Password: "
read password
# echo "length ${#password}"
if [ ${#password} -lt 6 ]
then
echo -e "\e[31mPlease use atleast 6 character of password.\e[0m"
else
pw=0
fi
done
pass=1
attempts=4
while [ $pass -ne 0 -a $attempts -ne 0 ]
do
echo "Confirm Password: "
read conf_password
if [ $conf_password = $password ]
then
pass=0
echo -e "\e[32mCongratulation! Your Username & Password Created Successfully!\e[0m"
echo $username >> user_name.csv
echo $conf_password >> password.csv
welcome
else
attempts=$(($attempts-1))
echo -e "\e[31mWrong Password! Remaining Attempts\e[0m = $attempts"
if [ $attempts -eq 0 ]
then
echo -e "\e[31mSorry! You crossed your maximum limit.\e[0m"
echo "Signup Again!"
sign_up
fi
fi
done
}
sign_in ()
{
header
echo -e "\e[32m<<<<<\e[0m Signin \e[32m>>>>>\e[0m"
users=(`cat user_name.csv`)
found=0
attempts=4
while [ $found -ne 1 -a $attempts -ne 0 ]
do
echo -e "\e[34mEnter Username:\e[0m "
read login_user
for user in `seq 0 $((${#users[@]}-1))`
do
#echo ${users[$user]}
if [ ${users[$user]} = $login_user ]
then
found=1
position=$user
#echo "User: $position"
fi
done
if [ $found -eq 1 ]
then
echo -e "\e[92m:) Great!\e[0m"
else
echo -e "\e[31mUsername does't exist\e[0m"
attempts=$(($attempts-1))
if [ $attempts -gt 0 ]
then
echo "Please try again"
echo "You have $attempts attempts remaining"
else
echo -e "\e[31mSorry! You crossed your maximum limit.\e[0m"
echo "Plaease Signup again"
welcome
fi
fi
done
password=(`cat password.csv`)
attempts=4
found=0
while [ $found -ne 1 -a $attempts -ne 0 ]
do
echo -e "\e[34mEnter Password:\e[0m "
read login_pass
echo
#echo "Position: $position"
#echo "Pass Position: ${password[$position]}"
if [ ${password[$position]}=$login_pass ]
then
# echo "Password Matched"
echo -e "\e[92mLogin Successful! You can start your exam.\e[0m"
start_test
found=1
else
echo -e "\e[31mWrong Password! Plase try again.\e[0m"
attempts=$(($attempts-1))
if [ $attempts -gt 0 ]
then
echo "You have $attempts attempts remaining"
else
echo -e "\e[31mSorry! No more attempts. Please try latter\e[0m"
welcome
fi
fi
done
}
start_test ()
{
header
echo -e "1) \e[32mTake the Test\e[0m"
echo -e "2) \e[31mExit\e[0m"
echo
read -p "Enter your choice: " choice
line=`cat question_bank.txt | wc -l`
case $choice in
1)
for i in `seq 5 5 $line`
do
#clear
#sleep 2s
header
echo
head -$i question_bank.txt | tail -5
echo
for j in `seq 10 -1 1` # ti
do
echo -e "\r\e[31mEnter the currect answer\e[0m \e[32m$j\e[0m : \c"
read -t 1 ans
if [ ${#ans} -ne 0 ]
then
break
fi
done
# echo "word count: ${#ans}"
# read -p "Choose the currect answer : " ans
if [ ${#ans} -eq 1 ]
then
echo "$ans" >> user_answer.txt
else
echo "No_Answer" >> user_answer.txt #
fi
echo
#echo "Next Question"
done
;;
2)
exit
;;
*) echo -e "\e[31mPlease choose currect option.\e[0m"
start_test
esac
results
}
results ()
{
header
c_ans=(`cat currect_answer.txt | tr -s ' ' | cut -d ':' -f1`)
c_ans1=(`cat currect_answer.txt | tr -s ' ' | cut -d ':' -f2`)
u_ans=(`tail -5 user_answer.txt`)
#echo "${c_ans[@]}"
#echo "${u_ans[@]}"
score=0
for i in `seq 0 $((${#c_ans[@]}-1))`
do
if [ ${c_ans[i]} = ${u_ans[i]} ]
then
echo -e "Q$(($i+1))) Your answer is : \e[32m${c_ans[i]} (Correct)\e[0m"
echo -e "\e[32mQ$(($i+1)))\e[0m \e[34mCurrect answer is :\e[0m \e[32m${c_ans[i]}. ${c_ans1[i]}\e[0m"
echo
score=$(($score+1))
else
echo -e "Q$(($i+1))) Your answer is : \e[31m${u_ans[i]} (Incorrect)\e[0m"
echo -e "\e[32mQ$(($i+1)))\e[0m \e[34mCurrect answer is :\e[0m \e[32m${c_ans[i]}. ${c_ans1[i]}\e[0m"
echo
fi
done
echo -e "\e[32mYour Total Score\e[0m: $score Marks"
echo
exit
}
header ()
{ sleep 2s
clear
echo ____________________________________________________
echo
echo -e "\e[32m<<<<<<<<<<<<<<<<<\e[0m \e[1;4mOnline MCQ Test\e[0m \e[32m>>>>>>>>>>>>>>>>>\e[0m"
echo -e "\e[31mTotal Marks\e[0m : 5 \e[31mTime\e[0m : 50 Seconds"
echo ____________________________________________________
}
#header
welcome ()
{
header
echo -e "1.\e[92mSignup\e[0m"
echo -e "2.\e[92mSignin\e[0m"
echo -e "3.\e[92mExit\e[0m"
echo
read -p "Please choose option : " choice
case $choice in
1) echo -e "\e[92mGreat! You are ready to Signup.\e[0m"
sign_up
;;
2) echo -e "\e[92mGreat! You are ready to Signin.\e[0m"
sign_in
;;
3) exit
;;
*) echo -e "\e[91mPlease choose currect option\e[0m"
welcome
;;
esac
}
welcome
#start_test
#results