Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用bash创建do-while循环?_Bash_Do While - Fatal编程技术网

如何使用bash创建do-while循环?

如何使用bash创建do-while循环?,bash,do-while,Bash,Do While,我希望菜单运行一次,然后询问用户是否希望再次运行,如果他们说是,它将继续运行,直到他们说否。我在网上看到了一些示例,但我不了解如何实现它 #Menu echo "Menu" echo "1. Display the message that indicates when the <script> command stared" echo "2. Dispay the message that indicates when the <script> command term

我希望菜单运行一次,然后询问用户是否希望再次运行,如果他们说是,它将继续运行,直到他们说否。我在网上看到了一些示例,但我不了解如何实现它

#Menu
echo "Menu"
echo "1. Display the message that indicates when the <script> command stared"
echo "2. Dispay the message that indicates when the <script> command terminated"
echo "3. game score"
read answer

if[[ $answer == 1 ]]; then
 echo""
elif[[ $answer == 2 ]]; then
 echo""
elif [[ $answer == 3]]; then
fi

echo "Do you want to repeat this routine?(Y/N)"
read yesno
#菜单
回声“菜单”
echo“1.显示指示命令启动时间的消息”
echo“2.显示指示命令何时终止的消息”
回声“3.游戏分数”
阅读答案
如果[[$answer==1]];然后
回声“”
elif[[$answer==2]];然后
回声“”
elif[$answer==3]];然后
fi
echo“是否要重复此例行程序?(是/否)”
阅读yesno
其他方法:

#the action functions
do_script_start() {
    echo "this is a message - start"
}
do_script_term() {
    echo "this is a message - term"
}
do_score() {
    echo "this is a game score"
}

# main 
ans=(
"Display the message that indicates when the <script> command stared"
"Dispay the message that indicates when the <script> command terminated"
"game score"
"exit menu"
)
PS3="Select what you want>"
select answer in "${ans[@]}"
do
case "$REPLY" in
    1) do_script_start ;;
    2) do_script_term ;;
    3) do_score ;;
    4) break ;;
esac
done
echo "here..."
#动作功能
do_script_start(){
echo“这是一条消息-开始”
}
do_script_term(){
echo“这是一个信息术语”
}
你得分吗{
echo“这是一个游戏分数”
}
#主要
ans=(
“显示指示命令启动时间的消息”
“显示指示命令何时终止的消息”
“比赛分数”
“退出菜单”
)
PS3=“选择您想要的>”
在“${ans[@]}”中选择答案
做
中的“$REPLY”案例
1) 是否开始编写脚本;;
2) 写一个术语;;
3) 你得分吗;;
4) 打破;;
以撒
完成
回声“这里…”

By
PS3=“Select what you want”
您指的是bash内部变量PS3?@geogevasiliou是的,
PS3
被用作
Select
提示符。我想先运行菜单,然后在他们选择了选项(1、2或3)并执行后,它会询问是否要再次运行菜单。可以吗?当然可以。这是可以做到的。在我的回答中,你可以找到每一件需要的东西。。。