Join Scott Simpson for an in-depth discussion in this video Solution: Make a script that uses input, part of Up and Running with Bash Scripting.
…So here's my result.…If I just run my script with no argument, I get a random…number, and if I use the argument Game, I get this fun guessing game.…I'll guess one.…No, that's not right.…Two?…Nope.…Three?…There it is, six.…I only got that on my sixth try.…I must be great at guessing.…Let's take a look at the script.…Up here at the top, I've got the shabang, and then…I set the variable Rand equal to the Bash random variable.…So every time this script runs, that'll generate a new value.…And then I set the variable secret equal to…the very first character in the string for random.…
I don't want my users having to guess a four or five digit random number,…so I'm just taking the first digit off of the string that Bash generates for me.…Let's go down to the bottom first.…So here, I'm asking if dollar sign one, which is the first argument, matches…game lower case, or game with a capital G, or game all in capital letters.…If it does, then I call the function game.…If not, I call the function generate.…So let's take a look at those functions.…
- What is Bash?
- Managing output with grep, awk, and cut
- Understanding Bash script syntax
- Creating a basic Bash script
- Displaying text with "echo"
- Working with numbers, strings, and arrays
- Reading and writing text files
- Working with loops
- Using functions
- Getting user input during execution
- Ensuring a response
Skill Level Beginner
1. Working with the Command Line
2. Building Bash Scripts
3. Control Structures
4. Interacting with the User
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.