gpt4 book ai didi

Linux 脚本计数器无法正常工作

转载 作者:太空宇宙 更新时间:2023-11-04 03:49:00 28 4
gpt4 key购买 nike

我正在做一个作业,我必须制作一个脚本,并且它似乎没有添加到计数器以在计数器达到一定数字时显示线索这是下面的代码

#!/bin/bash
#This is a game that is played by the user having to guess a number that the computer thinks of.
counter=0
# functions
function clueOne() {
echo “The number is over 50”
return
}
function clueTwo() {
echo “The number is smaller than 100 and is devided by 7, 10 times”
return
}


function selectANumber() {
dialog --backtitle "Number Game" --title "Number Game" --infobox "Thinking of a number..."
10 50 ; clear
}
selectANumber
# game starts here
while [ $counter -le 10 ]; do
read -p ”Guess my number human!”
if [ $counter -eq 5 ];
then
clueOne
counter=$((counter+1))
elif [ $counter -eq 9 ];
then
clueTwo
counter=$((counter+1))
elif [ $REPLY = 70 ];
echo “Yes that is my number!”;
exit 1
echo “Wrong number”
counter=$((counter+1))
fi
done
echo “Sorry you ran out of attempts”

最佳答案

因为如果你的柜台我们 0 说你不会进入任何 if else 梯子。因此,您可能想在完成之前增加计数器变量,即在 while 循环中,如下所示:

counter=$((counter+1))

并从 if else 梯形图中删除增量操作。

关于Linux 脚本计数器无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27036569/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com