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"
- 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.
- 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).
- You are required to modify the script, make a copy with the name guess_game.sh and implement the following changes:
- 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
- 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.
- When finishing the game, the script returns to the main menu, so the user can play again
- 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
- 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started