You are not logged in.
Hello fellow Arch users. Today I put the finishing touches on my first attempt at a real, practical program/bash-script for myself. It seems to work perfectly fine, but I would still be obliged if you would share your wisdom, critique my code, or just plain copy it and use it for yourselves. It is essentially a bare bones flashcard program, intended to help me review my Japanese vocabulary more efficiently, drawing from a hand made dictionary file. Below is the script.
/usr/bin/flashcards:
#!/bin/bash
# flashcard program
# openning message
clear
echo "This is Matt's flashcard program."
echo "It is copyright under the GNU/GPL."
echo "Press any key to continue."
echo -n ""
read NULL
clear
DECK=$1
# identify the number of words in the deck
WORDCOUNT=$(cat $DECK | wc -l)
# start of the loop
while true ; do
# view the word
NUMBER=$[ ( $RANDOM % $WORDCOUNT ) + 1 ]
LINE=$(cat $DECK | head -n $NUMBER | tail -n 1)
WORD=$(echo $LINE | cut -f 1 -d " ")
clear
echo "word: $WORD"
# identify how well the word is known
READING=$(echo $LINE | cut -f 2 -d " " | cut -f 1 -d " ")
MEANING0=$(echo $LINE | cut -f 3 -d " ")
# identify the correct answer to the multiple choice question
OPTION=$[ ( $RANDOM % 5 ) + 1 ]
# check if the word is known
echo -n "enter reading: "
read YOMIKATA
for X in $(seq 1 5) ; do
if [ $X == $OPTION ] ; then
echo "$X) $MEANING0"
else
NUMBERX=$[ ( $RANDOM % $WORDCOUNT ) + 1 ]
LINEX=$(cat $DECK | head -n $NUMBERX | tail -n 1)
MEANINGX=$(echo $LINEX | cut -f 3 -d " ")
if [ -z "$MEANINGX" -o "$MEANINGX" == "$WORD" -o "$MEANINGX" == "$MEANING0" ] ; then
MEANINGX="Line $NUMBER says - chicken butt!"
fi
echo "$X) $MEANINGX"
fi
done
echo -n "select reading: "
read ANSWER
if [ $ANSWER == $OPTION -a $YOMIKATA == $READING ] ; then
clear
echo "you got it right ... RIGHT ON!!!"
echo -n $LINE
read NULL
else
clear
echo "you got it wrong ... oh well"
echo -n $LINE
read NULL
echo $LINE >> better_study.txt
clear
UNKNOWN=$(wc -l better_study.txt | cut -f 1 -d " ")
if [ $UNKNOWN -gt 6 ] ; then
mv better_study.txt better_study_$(date +%Y.%m.%d~%H.%M.%S).txt
exit
fi
fi
# end of the loop
done
and here is a sample deck
science_vocab.txt
寂しい さびしい Sad
円滑 えんかつ Smoothness
安楽死 あんらくし Mercy death by request of family
尊厳死 そんげんし Mercy death by request of patient
引き起こす ひきおこす To cause
仮に かりに Temporary
解 かい Solution
橙色 だいだいいろ Bitter orange
矢印 やじるし Arrow
縮める ちぢめる To shorten
座標 ざひょう Coordinates
摩擦 まさつ Friction
固定する こていする To fix
机 つくえ Desk
滑らかな なめらかな Smooth
任意 にんい Arbitrary
強制振動 きょうせいしんどう Forced vibration
強制 きょうせい Coercion
減衰 げんすい Damping
単振り子 たんふりこ Simple pendulum
振り子 ふりこ Pendulum
微分 びぶん Integration
代入 だいにゅう Substitution
振動数 しんどうすう Frequency
現象 げんしょう Phenomenon
発条 ばね Spring
比例する ひれいする To be proportional
振動する しんどうする To oscillate
単振動 たんしんどう Simple harmonic motion
基盤 きばん Foundation
明確 めいかく Clarification
対策 たいさく Counter-measure
演習 えんしゅう Practice
講義 こうぎ Lecture
計算 けいさん Calculation
定期 ていき Regular
参考 さんこう Reference
所属 しょぞく Member
担当 たんとう To be in charge
詳細 しょうさい Detailed
提出 ていしゅつ To hand in
適用 てきよう Applying
補聴器 ほちょうき Hearing aid
濃度 のうど Concentration
熱力学 ねつりきがく Thermodynamics
平衡 へいこう Equilibrium
記号 きごう Symbol
媒 ばい Mediator
塩橋 えんきょう Salt Bridge
媒質 ようしつ Intermedium
So that is what I have. Any and all comments are much appreciated.
Thanks
~kiloecho7
Last edited by kiloecho7 (2008-07-07 11:51:25)
Offline