我正在尝试创建一个循环菜单脚本和我的主要 - 当二级菜单变为false时转向false ...您认为我需要修复什么?
#!/bin/bash
function f_menu_main () {
echo "1) option1";
echo "2) option2";
echo "3) option3";
echo "4) option4";
echo "99) exit";
}
function f_case_main () {
case $selection0 in
"1" ) function1; selection0="1"; ;;
"2" ) function2; selection0="2"; ;;
"3" ) function3; selection0="3"; ;;
"4" ) f_run_app packages 1; ;;
"99" | "q" | "exit" | "quit") selection0="exitl0"; ;;
*) f_menu_main; ;;
esac
}
function f_case_packages () {
case $selection1 in
"1" ) function1; selection1="1"; ;;
"2" ) function2; selection1="2"; ;;
"99" | "q" | "exitl" | "quit") selection1="exitl1"; ;;
*) f_menu_packages; ;;
esac
}
function f_menu_packages () {
echo "1) options";
echo "2) options";
echo "99) exit";
}
function f_run_app () {
selection="selection"$2;
exitlv="exitl"$2;
while [ "${!selection}" != "$exitlv" ]; do
echo "";
f_menu_$1;
echo "Last selection: \""${!selection}" "$2"\".";
echo -n "Select a item from menu: "; read "selection"$2;
f_case_$1;
done
}
f_run_app main 0;
我的假设是当selection1为exit1而1退出但while0也退出而变量selection0不是exit0。
答案 0 :(得分:1)
尝试将变量放在本地上下文中,看看是否有帮助。子弹可能会对其进行修改,并且在退出后不会将其恢复为原始值。
function f_run_app () {
local selection="selection"$2;
local exitlv="exitl"$2;
while [ "${!selection}" != "$exitlv" ]; do
echo "";
f_menu_$1;
echo "Last selection: \""${!selection}" "$2"\".";
echo -n "Select a item from menu: "; read "selection"$2;
f_case_$1;
done
}