Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a bash script named lab6s5 that plays a game with the user. When a user e

ID: 3808576 • Letter: C

Question

Create a bash script named lab6s5 that plays a game with the user. When a user executes the script, they must keep guessing the secret number until they successfully enter it.
Here is an example interaction with the script. Make sure that your script behaves identically:

$ ./lab6s5
I am thinking of a number between 1 and 10. Enter your guess:3 The secret number is larger than your guess. Try again.
I am thinking of a number between 1 and 10. Enter your guess:6 The secret number is smaller than your guess. Try again.
I am thinking of a number between 1 and 10. Enter your guess:2 The secret number is larger than your guess. Try again.
I am thinking of a number between 1 and 10. Enter your guess:5 Yes! 5 is the correct answer!

Explanation / Answer

#guessing a number and fitting it into a range 1 to 10

rand=$(($RANDOM%10+1))

echo 'I am guessing a number from 1 to 10'

echo 'Enter your guess'

read guess

#loop untill the condition is satisfied

while (($guess!=$rand)) ; do

   if [ $guess -lt $rand ]

   then

      echo 'Your guess is less than the secret number.'

   else

      echo 'Your guess is greater than the secret number.'

   fi

   echo 'Enter your guess'

   read guess

done

echo 'you guessed it! The number was ' $guess

echo 'Bye!!'

You can change the quoted strings if required. I tried my best to help you solve the problem. Hope you like it.