【发布时间】:2018-10-19 11:31:45
【问题描述】:
我对 Bash 脚本非常陌生,所以如果问题有些不连贯,请见谅。
如果用户回答“否”,我希望我的脚本重复一个问题 4 次,如果用户回答“是”,那么脚本可以退出,这就是我目前所拥有的
#!/bin/bash
echo "Would you like a cup of tea?"
read answer
while true;
do
if [ $answer = Y ] then
echo "Great, I'll make tea now"; then
break
if [ $answer = N ] then
echo "Are you sure?"
continue
if [ $answer = N ] then
echo "Are you sure?"
continue
if [ $answer = N ] then
echo "Are you sure?"
continue
if [ $answer = N ] then
echo "Ok, I give up!"
exit
fi
【问题讨论】:
标签: linux bash if-statement while-loop