Join Scott Simpson for an in-depth discussion in this video Selecting behavior using case, part of Learning Bash Scripting.
…So, what if you have a number of different things you want to test for?…Well, you could use a long series of if…statements, but there's a better way, the case statement.…Case checks a value against a series of values you provide, and it shows…up pretty often in conjunction with scripts…that take an argument to control an outcome.…I'll talk about those in more depth in the movie about arguments.…I'll set a variable a equal to dog.…Now, a case statement starts out with the word case,…followed by the variable you're testing, and then the word in.…Then on the next line, I'll put a condition to test.…
This will test if the value of a is equal to…cat, and a right parenthesis to indicate the end of that test.…That's followed up by whatever I want to do when the value matches.…In this case, echo feline, and then two semicolons…to tell Bash that you're done with that test.…And you can just keep adding test conditions.…You can use a pipe character to specify a list of things to match.…This will match dog or puppy, and if nothing matches…
- 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.