课程: Learning Linux Shell Scripting

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Guessing game

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…

内容