2014-11-20 2 views
0

메신저로 스크립트를 만들어야하는데 카운터가 특정 숫자에 도달했을 때 단서를 표시하는 데 카운터를 추가하지 않는 것 같습니다Linux 스크립트 카운터가 올바르게 작동하지 않습니다.

#!/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

귀하의 카운터가 0이라면 다른 사다리에 가보지 않을 것이기 때문입니다. 따라서 완료되기 직전에 카운터 변수를 증가 시키려면 while 루프와 같이 다음과 같이하십시오.

counter=$((counter+1)) 

그리고 다른 경우 사다리에서 증가 연산을 제거하십시오.

+0

죄송합니다. 조금 새로운 것이지만, 정확히 어떻게할까요? –

+0

신경 쓰지 마시고, 도와 줘서 고마워! –

+0

도움이되었다고 생각하면 답변을 수락하여이 질문을 닫으십시오. – SMA

관련 문제