尝试运行脚本向用户询问是/否答案的问题。如果是,则生成响应,如果没有,则向他们询问相同的问题4次。我尝试了很多变化,但仍然失败。 (我对脚本完全不熟悉!)
read -p "Would you like a cup of tea?"
if [ "RESP" = "yes" ]; then
echo "Great I will make you a cup of tea!"
else
[ "RESP" = "no" ]: then
echo [ "Are you sure you won't have a cup of tea?"
c=0
while [ $c -le 4 ]
count++
while [ $count -le 4 ]
fi
答案 0 :(得分:1)
您的脚本不正确请在脚本下面,并尝试了解它的工作原理。现在看看你的错误。
RESP
以下脚本适合您。如果您输入yes
并输入no
或任何其他字符串,则会退出4次。或者对yes
或no
以外的任何值进行无效响应等声明。希望这会对你有所帮助。
count=0
while [ $count -le 3 ]
do
read -p "Would you like a cup of tea?" RESP
if [ "$RESP" == "yes" ]; then
echo "Great I will make you a cup of tea!"
break
else
echo [ "Are you sure you won't have a cup of tea?"
count=$((count+1))
fi
done