以下是一段具有嵌套循环的shell代码,其中包含一个外部循环和一个内部循环。我想使用"break"语句来退出内部循环,但是似乎并没有起作用。请给出解决建议,在退出内部循环后显示用户第一个循环的选项。
#!/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
select
命令的内容。 - glenn jackman