O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required