18.4. Case statement
The case statement is a multiple-choice statement. You use case statements to match a value against a pattern. If the match is successful, you can execute commands based purely on this match. Here’s the format of the ‘ case ’ statement:
case value in pattern1) commands1 ... ;; pattern2) commands2 ... ;; esac
Here’s how case works. The word after the value must be ‘in’, and each pattern must be terminated with a right bracket. The value can be a variable or a constant. When a match is found against a pattern all commands are then executed for that pattern up to the ;;.
The value will check each pattern for a match. Once a pattern is matched, it will not continue with the other patterns even after it has executed ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access