如何解决为什么是无限循环 - Bash 中的简单游戏脚本
编写一个简单的游戏脚本来猜出 42 的正确数字。
我在 for/else 语句中得到一个无限循环。有人可以告诉我为什么吗?我对 Bash 非常陌生
谢谢
#!/bin/bash
read -p "Please pick a number between 1 and 100: " x
q=exit
while true
do
if [ "$x" = "q" ]
then
exit
fi
#done
if [ "$x" -gt "42" ]; then
echo -e "That number is too high!"
else read -p "try again :"
fi
if [ "$x" -lt "42" ];
then echo -e "That number is too low!"
else read -p "try again :"
fi
if [ "$x" = "42" ] ;
then echo -e "You are Correct!!!"
else read -p "try again :"
fi
done
exit
解决方法
此行填充 $x
:
read -p "Please pick a number between 1 and 100: " x
此行填充 $REPLY
:
read -p "try again :"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。