0

I'm making a random number guessing game, but I want it to last longer than one guess, when u guess wrong it adds one to ded. and repeats from a certain point (I'll add STARTHERE where it needs to start again). I know theres a command in Windows with:

:hello script goto hello.

But this doesn't work in Ubuntu Bash. Here's my script.

number=$(( (RANDOM % 100)  + 1 ))

echo $number # Just for testing purposes
 # STARTHERE (This is not in the script)
read guess
if [ $guess = $number ];
then
echo "Cool! You won!"

elif [ $guess > $number ]
then
echo "not needed"

elif [ $guess < $number ]
then
echo "not needed rn"
fi

( & = 1 )
elif [ $guess =/= $number ]
then
ded=&((  (+ 1) ))

fi
  • 1
    Jumps/gotos are discouraged because they lead to spaghetti code. You could use a loop instead. – Socowi Apr 24 '17 at 14:36
  • Can you reduce the example to the required minimum, as in remove all the comments and other fluff? It's just distracting (and also making the syntax invalid). – Benjamin W. Apr 24 '17 at 14:36
  • 1
    Nevermind, I just found out how loop worked. I thought it was a command put in the script and it loops the whole thing until it gets stopped somehow. Thanks, Socowi. -------- (Sorry, I'm new to BASH Scripting, as I'm only in Highschool) – GlitchyShadowZ Apr 24 '17 at 14:59
  • See: [GuessingGame/src/guess.bash](https://github.com/brendangregg/GuessingGame/blob/master/src/guess.bash) – agc Apr 25 '17 at 06:17

0 Answers0