我怎样才能让程序回到开始处?

我怎样才能让程序回到开始处?

所以我有我的程序,但我不知道如何让程序循环回到开始。我有更多的程序,但是这是我希望程序重新启动的部分,如果我选择是,退出 0 和退出 1 目前是占位符,因为我不知道如何让它循环。提前感谢您的帮助。

echo "Is that all sir? (Yes/No)"

if [ $word = "Yes" ] 
then exit 0

if [ $word = "No" ]
then exit 1

fi

答案1

response=no
while [[ "$response" != "yes" ]]
do
    echo "Is that all? (Yes/No)"
    read -r response
done

参考与建议:

答案2

#!/usr/bin/env bash

# While running an infinite loop
while [ 1 ]; do
    # keep asking the user for input (Yes/No).
    echo "Is that all sir? (Yes/No): "
    # the read keyword assigns the input to the word variable
    read word
    # If the user types "Yes" 
    if [ $word = "Yes" ]; then
        # break the loop and finish the script.
        break
    fi
done

相关内容