Sponsored Content
Top Forums Shell Programming and Scripting bashscript for learning definitions Post 302450257 by phr0st on Thursday 2nd of September 2010 04:45:04 AM
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
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
SHAPE_STDVAR(7) 					 Miscellaneous Information Manual					   SHAPE_STDVAR(7)

NAME
shape_stdvar - shapeTools RMS project wide variant definitions DESCRIPTION
This file contains common variant definitions to be used in a software development project supported by the shape release management sys- tem. The stdvar file defines a variant raster for a whole development project. This central definition facility unifies the naming and semantics of supported system variants. Stdvar is to be included into the Shapefiles of any part of the developed system via shape's include mechanism. The definitions in stdvar should be carefully designed and maintained for each supported project. They usually concern variant control for all hardware/operating system platforms to be supported or variant settings to produce different qualities of generated code (debug or optimized). Enclosed in the shapeTools distribution, you find the stdvar file used in the development of the shape toolkit itself. This may be a good starting point for developing an own variant raster. At least, it helps you learning the definition syntax. Otherwise, for a description on the syntax of variant definition parts see the shape(1) manual. FILES
$(SHAPELIBPATH)/stdvar SEE ALSO
shape_RMS(1), shape (1) 24.8.119 SHAPE_STDVAR(7)
All times are GMT -4. The time now is 07:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy