bashscript for learning definitions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bashscript for learning definitions
# 1  
Old 09-02-2010
bashscript for learning definitions

Hi, I am a german lawstudent and have to learn a few hundred definitions and laws in the next months. I thought it would be cool to have a little helper, a bashscript which is working with flat textfiles. I found one in the archlinuxforum which was almost perfect...almost. It is on some point based on cut, so I am not able to exclude spaces as delimiters. Google said it would be better to use awk instead of cut. Problem is, this is the first bashscript I am working with and I should spend time with my lawbooks and not with scripting. It would be cool, if someone could help me.

Code:
#!/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

# Zähle alle Karteikarten
KARTEIGROESSE=$(cat $DECK | wc -l)

# Starte die Schleife
while true ; do

# Zeige die Frage
    NUMBER=$[ ( $RANDOM % $KARTEIGROESSE )  + 1 ]
    ZEILE=$(cat $DECK | head -n $NUMBER | tail -n 1)
    FRAGE=$(echo $ZEILE | cut -f 1 -d ">")
    clear
    echo "Frage: $FRAGE"

# Prüfe die einschlägigen Paragraphen
    PARAGRAPHEN=$(echo $ZEILE | cut -f 2 -d ">" | cut -f 1 -d ">")
    ANTWORT0=$(echo $ZEILE | cut -f 3 -d ">")

# Suche die korrekte ANTWORT0 der MC-Frage
    OPTION=$[ ( $RANDOM % 5 )  + 1 ]
    
# Prüfe, ob die Anwort richtig war
    echo -n "enter PARAGRAPHEN: "
    read KARTEI
    for X in $(seq 1 5) ; do
        if [ $X == $OPTION ] ; then
            echo "$X) $ANTWORT0"
        else
            NUMBERX=$[ ( $RANDOM % $KARTEIGROESSE )  + 1 ]
            ZEILEX=$(cat $DECK | head -n $NUMBERX | tail -n 1)
            ANTWORTX=$(echo $ZEILEX | cut -f 3 -d ">")
            if [ -z "$ANTWORTX" -o "$ANTWORTX" == "$FRAGE" -o "$ANTWORTX" == "$ANTWORT0" ] ; then
                ANTWORTX="ZEILE $NUMBER macht whargarrgl!"
            fi
            echo "$X) $ANTWORTX"
        fi
    done
    echo -n "Wähle die Antwort: "
    read VERSUCH
        if [ $VERSUCH == $OPTION -a $KARTEI == $PARAGRAPHEN ] ; then
            clear
            echo "Richtig, weiter so!"
            echo -n $ZEILE
            read NULL
        else
            clear
            echo "Falsch, versuchs nochmal!"
            echo -n $ZEILE
            read NULL
            echo $ZEILE >> wiederholen
            clear
            UNKNOWN=$(wc -l wiederholen | cut -f 1 -d ">")
            if [ $UNKNOWN -gt 6 ] ; then
                mv wiederholen $(date +%Y.%m.%d~%H.%M.%S)wiederholen
                exit
            fi
        fi

# Beende die Schleife
done

Every line in the deck contains something like:

What should one do if the judge does X? [delimiter] § 280 Abs.1,3 i.V.m. § 281 BGB [delimiter] One should aks for Y as allowed in § 280 Abs.1,3 i.V.m. § 281 BGB. EOL

Link to original script:
http://bbs.archlinux.org/viewtopic.php?id=51375
# 2  
Old 09-03-2010
The best way with your request is to provide some sample input, and the expect output firstly.
# 3  
Old 09-03-2010
Ok, I'll try:
I have textfiles with the scheme:

question [delimiter] paragraphs [delimiter] answer

Single lines are working as cuecards/flashcards. When I run the script the following happens:

1.The script ist showing me the question (field one).
2.I have to enter the correct value of paragraphs (field two).
3.Then there is a multiple choice test with five random answers that are numbered (field three) and I have to choose the correct one by pressing sth between 1-5.
4.If I am right next question will be asked.
5.If I am wrong the whole line will be copied to another textfile for repetition

Since the tool "cut" counts every space as a delimiter, it works for single words (like vocabulary). But my questions and answers are complete sentences, so the script counts all my answers as wrong.
Basically I am looking for something like a flashcard/cuecard software, based on plain textfiles and as less dependencies as possible (no java, python, etc).

I am sorry, if my post is hard to understand or doesn't meet the formal standards of this board, please correct me.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to parse the multiple definitions from a single line and assign

Hi, I need a help on my requirement that eg: NEED="TEST=Name WORK=Ps DEL=let" Here the definition can be n number, could anybody have an idea to get the output as, TEST=Name WORK=Ps DEL=let .. .. till the 'n' definitions listed. Any suggestions please..... Regards, ricky (6 Replies)
Discussion started by: ricky-row
6 Replies

2. Programming

Where are the library function definitions located?

Hi friends, I hope everyone is doing fine. I have this confusion, hope you can help me out with it. The header files contain only function prototypes. Where are the function definitions located. For example, if I would like to see how printf works, where can I see its definition, stdio.h only... (2 Replies)
Discussion started by: gabam
2 Replies

3. UNIX for Dummies Questions & Answers

Definitions/explanations

Just wondering: Can anyone tell me what is meant by the term 'interactive shell" or 'built-in commands' - for example, if I type 'man set' I get a page listing all the 'built in commands' but no explanation of what they are as a concept or what they do. And while I'm here: I was wondering as... (5 Replies)
Discussion started by: Straitsfan
5 Replies

4. AIX

/etc/subsync parms definitions ?

In our Cron table, we have the /etc/subsync client ipadr1 ipadr2 Each ipadr is an actual IP adress. I think it has something to do with synchronizing the clock between servers, but what is the ipadr2 for ? (0 Replies)
Discussion started by: Browser_ice
0 Replies

5. UNIX for Dummies Questions & Answers

Shell and commandline interpreter-definitions

What is the difference between the(a) shell and the (a) command-line interpreter? Here we're talking about the complete dummy question, but could someone point me right. (yes, have written scripts in for instance bash shell, and and grepp-ed my way around ....:eek: (4 Replies)
Discussion started by: amkgw
4 Replies

6. Virtualization and Cloud Computing

EPTS: Proposed Event Processing Definitions, September 20, 2006

Tim Bass 08-20-2008 10:47 PM For interested readers, here are the event processing definitions we provided to the (future) EPTS working group on September 20, 2006, coordinated (edited)*by David Luckham and Roy Schulte; adaptive process management (n.) an element of resource and business... (0 Replies)
Discussion started by: Linux Bot
0 Replies

7. Shell Programming and Scripting

Missing alias definitions after involve another shell

I setup alias on my .bash_profile. It works very will until I did another sh on command prompt. I typed alias on new shell and all the definitions did not carry over. How to correct this? Thanks in advance. (9 Replies)
Discussion started by: wangzosen
9 Replies

8. Shell Programming and Scripting

function definitions file for bc

Hello, All :) ...I just figured out how to setup a function definitions file for bc...I was going to create lots more functions for it, but I'll bet that a huge file with tons of definitions has already been written...? Thanx in advance for any replies, Pudnik (0 Replies)
Discussion started by: Pudnik
0 Replies

9. Linux

Termcap Definitions

Hi. How do I enter and escape from graphics mode on RedHat Linux to capture escape sequences. I'm trying to edit the system termcap. (2 Replies)
Discussion started by: cstovall
2 Replies
Login or Register to Ask a Question