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

时间:2017-03-10 22:03:00

标签: 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 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

1 个答案:

答案 0 :(得分:3)

其他方法:

#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..."