From the course: CompTIA Linux (XK0-005) Cert Prep
Unlock the full course today
Join today to access over 23,100 courses taught by industry experts.
Conditional flow with case - Linux Tutorial
From the course: CompTIA Linux (XK0-005) Cert Prep
Conditional flow with case
- [Instructor] Generally we use IF conditionals in Bash. However, in cases where we're matching more than one pattern with an ifthen elseif conditional block, it may be more efficient to use a case statement. The case statement evaluates the condition one time and acts accordingly. This statement evaluates the age variable. If the value is one through nine numerically, then it executes the action list to the right of the parentheses until the double semicolons, which is the action list terminator, The characters do the left of the parentheses make up a glob. You can do pattern matching in the same manner as you would on the command line using wild cards, character sets, and character classes. However, you cannot use regular expressions, which is unfortunate. The equivalent IF condition would evaluate age up to four times to do the same thing so this case statement would be much faster. The last condition, which is…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
What makes a shell script a shell script?3m 18s
-
(Locked)
Positional arguments4m 4s
-
(Locked)
File globbing2m 3s
-
(Locked)
Wildcards4m 42s
-
(Locked)
Bash variable scope1m 17s
-
(Locked)
Output to STDOUT and STDERR1m 55s
-
(Locked)
Pipe data into a script3m 2s
-
(Locked)
Conditional flow with if, then if3m 12s
-
(Locked)
Conditional flow with case2m 21s
-
(Locked)
Numeric conditions3m 45s
-
(Locked)
String conditions57s
-
(Locked)
File conditions1m 33s
-
(Locked)
For loop2m 42s
-
(Locked)
While loop1m 30s
-
-
-
-
-
-