From the course: LPIC-1 Exam 102 (Version 5.0) Cert Prep

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Conditional flow with case

Conditional flow with case - Linux Tutorial

From the course: LPIC-1 Exam 102 (Version 5.0) Cert Prep

Start my 1-month free trial

Conditional flow with case

- [Instructor] Generally, we use if conditionals and Bash. However, in cases where we're matching more than one pattern with an if, then else-if 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 to the left of the parenthesis make up a glob. You can do pattern matching in the same manner as you would on the command line using wildcards, character sets, and character classes. However, you cannot use regular expressions which is unfortunate. The equivalent if conditional 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…

Contents