From the course: Learning Bash Scripting
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Selecting behavior using "case" - Bash Tutorial
From the course: Learning Bash Scripting
Selecting behavior using "case"
- [Instructor] The case statement is a control structure which lets us define code to run based on particular conditions. We provide it a series of values and whichever one matches the given input is what Bash runs. A case statement starts out with the word case followed by a variable that you're testing and the word in. I'll start my script by defining a variable. I'll write animal equals dog. Then I'll write case, provide that variable to test and provide the keyword in. Then on the next line, I'll put a condition to test. (keyboard clicks) This will test if the value of the variable animal is equal to bird. That test condition comes before a right parenthesis to indicate the end of the test. That's followed up by whatever I want to do when the value matches. And then two semicolons to tell bash that you're done with this condition, and you can keep adding test conditions. We can use the pipe character to…
Contents
-
-
-
-
-
Conditional statements with the "if" keyword4m 17s
-
(Locked)
Working with "while" and "until" loops3m 57s
-
(Locked)
Introducing "for" loops4m 22s
-
(Locked)
Selecting behavior using "case"2m 11s
-
(Locked)
Using functions6m 17s
-
(Locked)
Reading and writing text files3m 25s
-
(Locked)
Challenge: Build a script using control structures33s
-
(Locked)
Solution: Build a script using control structures1m 18s
-
-
-
-