0

So i got the function RM_OBJ_P which gets called from the menu page PAGE_RM. This is working, you can enter all the funky filenames you know and if they are in the database, the output gets printed to a text file (just as i want it to be). But if i ever foolishly choose the somehow "magical" option x (or X) which should call PAGE_RM, the script exits. What have i done wrong?
(I also tried to achieve this by using return 0 instead of PAGE_RM)

EDIT: Obviously entering xas choice also calls RM_P_* (see added log)

RM_OBJ_P() {
echo "After you have finished, you can find the file here: $ACTIVE_DB/remove.txt"
echo
if [ ! -f file.txt ] ; then
    read -p "Please enter the name of the file you'd like to check (or x to return): " CHOICE
    case "$CHOICE" in
        *) RM_P_N ;;
        x|X) PAGE_RM ;;
    esac
else
    read -p "Please enter the name of the file you'd like to check: " CHOICE
    echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" >>$ACTIVE_DB/remove.txt
    echo "If you want to remove $CHOICE, please consider this:" >>$ACTIVE_DB/remove.txt
    case "$CHOICE" in
        *) RM_P_E;;
        x|X) PAGE_RM ;;
    esac
fi
}

In case it matters, RM_P_N and RM_P_Eare both like this (and work as intended)

RM_P_*() {
echo "something gets an echo echo echo o o o" >file.txt
PATH/TO/perl_script.pl "$CHOICE" database_query >>file.txt
RM_OBJ_P
}

and last but not least, PAGE_RM

PAGE_RM() {
    clear
    while :; do
        PRINT_BANNER_S
        PRINT_RM_MENU
        echo "single - view"
        echo "print  - print"
        PRINT_LINE
        echo "x      - go back"
        PRINT_LINE3
        read -p "CHOICE: " CHOICE
            case "$CHOICE" in
                s|S) RM_OBJ ;;
                p|P) RM_OBJ_P ;;
                x|X) return 0
                PRINT_LINE
            esac
    done
}

Here the relevant part of the log

+ RM_OBJ_P
+ echo 'After you have finished, you can find the file here: DB_45763/remove.txt'
+ echo
+ '[' '!' -f DB_45763/remove.txt ']'
+ read -p 'Please enter the name of the file you'\''d like to check: ' CHOICE
Please enter the name of the file you'd like to check: + echo '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
+ echo 'If you want to remove x, please consider this:'
+ case "$CHOICE" in
+ RM_P_E
+ echo 'If you want to remove x, please consider this:'
+ ./files/perls/remove_object.pl x dbi:SQLite:dbname=test.sqlite '' ''
0

Nevermind, solved it this way
[nice example of think before you (speak) ask]. If anyone has a better solution, feel free to answer

RM_OBJ_P() {
echo "After you have finished, you can find the file here: $ACTIVE_DB/remove.txt"
echo
if [ ! -f $ACTIVE_DB/remove.txt ] ; then
    read -p "Please enter the name of the file you'd like to check (x to abort): " CHOICE
    if [[ $CHOICE = x ]] ; then
        PAGE_RM
    else
        RM_P_N
    fi
else
    read -p "Please enter the name of the file you'd like to check (x to abort): " CHOICE
    echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" >>$ACTIVE_DB/remove.txt
    echo "If you want to remove $CHOICE, please consider this:" >>$ACTIVE_DB/remove.txt
    if [[ $CHOICE = x ]] ; then
        PAGE_RM
    else
        RM_P_E
   fi
fi
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.