RM_OBJ_P
所以我得到了从菜单页面调用的函数PAGE_RM
。这是有效的,您可以输入您知道的所有时髦文件名,如果它们在数据库中,则输出将打印到文本文件中(正如我想要的那样)。但如果我愚蠢地选择了应该调用的某种“神奇”选项x
(或) ,脚本就会退出。我做错了什么? (我也尝试通过使用而不是 来实现这一点)X
PAGE_RM
return 0
PAGE_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
}