【发布时间】:2023-01-04 01:12:54
【问题描述】:
我开始学习 shell 脚本,我正在尝试找出一种方法来添加一个选项,使用户返回到菜单。 例如:
5) echo "Return to the menu"
echo "Return back to the menu? ";;
听到的是手头的剧本:
echo "1. I'm number one"
echo "2. I'm number two"
echo "3. I'm number three"
echo "4. Exit from menu "
echo -n "Enter one the following numbers:"
while :
do
read choice
case $choice in
1) echo "You have selected the number one"
echo "Selected number is one";;
2) echo "You have selected the number two"
echo "Selected number is two";;
3) echo "You have selected the number three"
echo "Selected number is three";;
4) echo "Exiting after the information have been received by both devices" # Referring to the TCP/IP protocol. The information has to be established by both client and device to act like a server before data is sent. Ok I'm showing of here :)
exit;
esac
echo -n "Enter one of the four options"
done # Sorry if there are errors in the this code, I wrote it on the fly :)
【问题讨论】:
-
这将有助于解释您的代码当前的作用以及您希望输出如何不同。选项 1-3 应该退出循环吗?