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

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…

Contents