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
|
# display question, possible answers, then process reply
# Copyright (C) 2011-2019 John Nogatch <jnogatch@gmail.com>
# collect info
(NR==1){answer = $0; key = $2; gsub( /[^A-D]/, "", key); next}
# display question and possible answers
{print $0; next}
# read response from stdin, if wrong, print correct answer info and wait for ack
END {
# read user's response
if (getline < "/dev/stdin" != 1)
exit 2
# convert to upper case
response = toupper( $1)
# check for "quit"
if (response == "Q")
exit 2
# check for incorrect response
if (response != key) {
print "*******" answer "\nto continue, hit Enter"
if (getline < "/dev/stdin" != 1)
exit 2
exit 1
}
# response was correct
print ".......correct\n"
exit 0
}
|