shell脚本 关于做一个菜单,然后从二级菜单返回到主菜单,如何实现
1个回答
展开全部
#!/bin/bash
# Bash Menu Script Example
mainmenu()
{
PS3='Please enter your choice: '
options=("Option 1" "Option 2" "Option 3" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Option 1")
submenu
;;
"Option 2")
echo "you chose choice 2"
;;
"Option 3")
echo "you chose choice 3"
;;
"Quit")
exit
;;
*)
echo invalid option
;;
esac
done
}
submenu()
{
PS3='Please enter your choice: '
options=("Option 1" "Option 2" "Option 3" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Option 1")
echo "you chose sub 1"
;;
"Option 2")
echo "you chose sub 2"
;;
"Option 3")
echo "you chose sub 3"
;;
"Quit")
mainmenu
;;
*)
echo invalid option
;;
esac
done
}
mainmenu
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询