-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflashcard
More file actions
executable file
·32 lines (26 loc) · 778 Bytes
/
flashcard
File metadata and controls
executable file
·32 lines (26 loc) · 778 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
#!/bin/sh -e
help() {
cat - >&2 <<EOF
flashcard - for memorizing things
flashcard file...
The lines of the file should be formatted like front=back where
"front" is the information to be presented to you and "back" is the
corresponding information you should reply with. The script will tell
you whether or not you were correct, and present the correct answer to
you if you were incorrect.
EOF
}
case "$1" in --help|-h) help; exit 0 ;; esac
tty=$(tty)
cat "$@" | shuf | while IFS='=' read -r front back; do
printf '%s\n> ' "$front"
read -r response < "$tty"
case "$response" in
"$back")
printf '\n----------------\nCorrect!\n----------------\n\n'
;;
*)
printf '\n----------------\nThe correct answer was %s\n----------------\n\n' "$back"
;;
esac
done