【发布时间】:2017-07-12 07:27:50
【问题描述】:
我正在尝试在我的 bash 脚本中实现一个 prev 选项以返回到之前的“菜单”,以及在没有为 @987654323 设置变量时脚本再次询问用户输入的方法@。
这是我的 bash 脚本:
#!/bin/bash
#Menu() {
for (( ; ; ))
do
beginORload=
echo "Choose option:"
echo "1 - Begin"
echo "2 - Load"
read -p "?" beginORload
#}
#Begin() {
if [ "$beginORload" -eq "1" ]
then
clear
for (( ; ; ))
do
echo "Beginning. What is your name?"
read -p "?" name
#If "prev" specified, go back to #Menu()
if [ "$name" -eq "prev" ]
then
Menu
fi
#If nothing specified, return to name input
if [ -z ${name+x} ]
then
Begin
else
break
fi
echo "Hi $name !"
done
fi
done
在批处理中,我可以简单地做:
:menu
echo Choose option:
echo 1 - Begin
echo 2 - Load
[...]
:begin
[...]
if "%name%==prev" goto menu
if "%name%==" goto begin
问题是我到处都遇到错误,我不知道要输入什么才能让它工作
顺便说一句,我正在运行优胜美地。谢谢你
【问题讨论】:
-
您只需要使用
case或select- 请参阅此处的第6 章:mywiki.wooledge.org/BashGuide/TestsAndConditionals -
谢谢!我会试试这个
-
我仍在努力让它发挥作用。请问还有什么帮助吗?