Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何创建正常运行的程序?因为我的程序一直在运行,不会停止_Linux_Bash_Shell - Fatal编程技术网

Linux 如何创建正常运行的程序?因为我的程序一直在运行,不会停止

Linux 如何创建正常运行的程序?因为我的程序一直在运行,不会停止,linux,bash,shell,Linux,Bash,Shell,我的英语很差,但我正在努力解释我的问题。 我想在bash上创建一个小程序,用户必须在其中猜测数字。但我的计划没有尽头 我是bash脚本的新手,但我每天都在努力做得更好。 我用的是CentOS 7。我转到/usr/bin/local并创建一些文件,给他chmod+x并用gedit打开: #!/usr/bin/bash #This script should ask us our name and play the game "Guess the Number" with us. echo "W

我的英语很差,但我正在努力解释我的问题。 我想在bash上创建一个小程序,用户必须在其中猜测数字。但我的计划没有尽头

我是bash脚本的新手,但我每天都在努力做得更好。 我用的是CentOS 7。我转到/usr/bin/local并创建一些文件,给他chmod+x并用gedit打开:

#!/usr/bin/bash

#This script should ask us our name and play the game "Guess the Number" with us.

echo "What is your name?"
read name
echo "Hello $name"
echo "I want to play $ name with you, you have to guess the number from 1 to 10)"
echo "Are you ready?"
read rdy


answer=$(( answer = $RANDOM % 10 ))


read -p "Enter your number: " variant 
     while [ $answer != $variant ]; do

if [ $answer -gt $variant ]; then 
     echo "Your number is bigger, try again"

elif [ $answer -lt $variant ]; then
     echo "Your number is smaller, try again"

  continue

fi

done

eternal "Your number is smaller/bigger"
until you press ctrl+c
我需要做什么,请帮忙。我知道非业余爱好者不喜欢新手,但我需要你的帮助,告诉我我的错误,我会变得更好。谢谢

你打电话吗

#!/bin/bash
echo "What is your name?"
read name
echo "Hello $name"
echo "I want to play  with you, you have to guess the number from 1 to 10"


answer=$(( $RANDOM % 10 ))

while true
do
    read -p "Enter your number: " variant
    if [ "$answer" -gt "$variant" ]; then
        echo "The number is bigger, try again"

    elif [ "$answer" -lt "$variant" ]; then
        echo "The number is smaller, try again"
    else
        break;
    fi

done
echo "Yes, the answer was ${answer}"
read -p "Enter your number: " variant
while
循环之前

在循环中,您永远不会更改
变量
,因此原始值将在
while
条件中重新使用。永远


您可以从
variant=-1
开始,将
read
移动到循环内,或执行类似@xiawi的操作。

read-p“输入您的号码:”variant while[$answer!=$variant]读取变量并在循环endlessy中检查它,而不是每次更改它。我猜你想读循环中的变量。另外,通过运行脚本并记住引用变量。非常感谢!我需要练习。谢谢