有以下shell,它在(while true)循環中有一個(while true)循環。我試圖用「休息」打破內部循環,但事實並非如此。 我想打破內循環&顯示用戶第一循環的選項;建議請。Shell break while-true循環
#!/bin/ksh
sub_menu() {
echo "~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " S U B - M E N U "
echo "~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "1. Display properties"
echo "2. Back"
}
read_sub_options(){
echo "Please select option"
read option
case $option in
1) sub_menu ;;
***2) break ;;***
*) echo "Please insert options 1 ~ 2";;
esac
}
showSubMenu(){
while true
do
sub_menu
read_sub_options
done
}
read_options(){
echo "Please select option "
read option
case $option in
1) showSubMenu ;;
2) exit 0;;
*) echo "Please insert options ";;
esac
}
show_menus() {
echo "~~~~~~~~~~~~~~~~~~~~~"
echo " M A I N - M E N U "
echo "~~~~~~~~~~~~~~~~~~~~~"
echo "1. Sub Menu"
echo "2. Exit"
}
# -----------------------------------
# MAIN
# ------------------------------------
while true
do
show_menus
read_options
done
這裏是輸出:
~~~~~~~~~~~~~~~~~~~~~
M A I N - M E N U
~~~~~~~~~~~~~~~~~~~~~
1. Sub Menu
2. Exit
Please select option
1
~~~~~~~~~~~~~~~~~~~~~~~~~
S U B - M E N U
~~~~~~~~~~~~~~~~~~~~~~~~~
1. Display properties
2. Back
Please select option
2
~~~~~~~~~~~~~~~~~~~~~~~~~
S U B - M E N U
~~~~~~~~~~~~~~~~~~~~~~~~~
1. Display properties
2. Back
Please select option
2
閱讀ksh手冊頁中的'select'命令。 – 2012-03-08 22:29:38
+1對於好的問題描述,樣本輸出和一些實際的代碼。祝你好運。 – shellter 2012-03-09 00:20:43
@shellter非常感謝! – sid 2012-03-09 04:22:10