Question: UNIX Shell Programming For this exercise you are required to make a copy of the following script into a file named guess.sh : #!/bin/tcsh -f

UNIX Shell Programming

For this exercise you are required to make a copy of the following script into a file named guess.sh:

#!/bin/tcsh -f

echo "guess the number"

set answer = $<

set goal= `tr -dc A-Za-z0-9 < /dev/urandom | od -d | head -c 10 | tr -d 0 | tr -d ' '`

set count = 1

while ($answer != $goal )

if ($answer < $goal ) then

echo "too small"

else

echo "too large"

endif

@ count ++

set answer = $<

end

echo "correct!"

echo "using $count rounds"

  1. Study the script and be sure to understand it. Review the slides about Shell Overview and Shell Programming with the description of what it does. Your task is to incorporate comments in different parts of the script to explain what it does.
  2. Execute the script and correct any error it may have to run it. You will have to change permissions to the shell script file to make it executable (remember the chmod command).
  3. You are required to modify the script, make a copy with the name guess_game.sh and implement the following changes:
    1. Create a main menu, so when you execute the script the user will have two options (try the command clear to clean the screen):

1.Run the guessing game

2.Exit

  1. When the user selects run the game, the game will do the same thing with an addition. It should now keep a record of each score.
  2. When finishing the game, the script returns to the main menu, so the user can play again
  3. When the user selects Exit, the script before ending will print out to the screen the different scores for each game that was played:

Exiting the guessing game

Your average of rounds is: calculated average

Your scores are:

5

6

4

3

4

  1. See if using the exit status of a command may be of any help.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!