From the course: Learning Linux Shell Scripting

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Guessing game

Solution: Guessing game - Linux Tutorial

From the course: Learning Linux Shell Scripting

Start my 1-month free trial

Solution: Guessing game

- [Instructor] So, how did you do at this challenge? Let me show you my solution. From the terminal I'm gonna do touch guess.sh, change mode 755 guess.sh and atom guess.sh. Then we do our shebang. Usr/bin/env bash. Now, we're gonna create a global variable computer which is gonna hold the computer's guess. Normally we would put a random in here. There is a random in the Bash shell but that's a problem for another day and we'll just that it's equal to 50 and we're gonna create one more global variable and we're going to call it playing and set it to zero. Then we're gonna do a while loop and in the while loop we're gonna do square brackets braces $PLAYING and we're gonna say -eq for equals, zero, so while playing is equal to zero, we're gonna continue in this loop. Then we're gonna have a do and a done and in the middle. First thing we're gonna do is we're gonna read some input from the user. So, we're gonna say read -p and then prompt the user what's your guess colon with a space and…

Contents