関数が呼び出されず、スクリプトが終了しました。

関数が呼び出されず、スクリプトが終了しました。

RM_OBJ_Pだからメニューページから呼び出される関数を得ましたPAGE_RM。これはうまくいきます。知っているすべてのファンキーなファイル名を入力でき、そのファイル名がデータベースにある場合、出力はテキストファイルとして印刷されます(私が望んでいたように)。ただし、x呼び出す必要がある「魔法」オプションを愚かに選択すると、スクリプトは終了します。私は何が間違っていましたか? (私は代わりにこれを使ってこれを達成しようとしました)XPAGE_RM
return 0PAGE_RM

編集:明らかにx選択入力も呼び出されますRM_P_*(追加ログを参照)。

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
}

重要RM_P_Nで、どちらもこれがRM_P_E期待どおりに機能する場合

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
}

最後に重要なのは、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
}

以下はログの関連部分です。

+ 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 '' ''

ベストアンサー1

大丈夫です、
[尋ねる前に考える良い例]このように解決してください。より良い解決方法がある場合は、答えてください。

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
}

おすすめ記事