为什么这个无限循环 - Bash 中的简单游戏脚本
Why is this Infinite Looping - Simple Game script in 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 :"
编写一个简单的游戏脚本来猜出 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 :"