Each time you type a command line at a shell prompt, you can see what happens and decide what command to run next. But a shell script needs to make decisions like that itself. A case statement helps the script make decisions. A case statement compares a string (usually taken from a ) to one or more patterns. The patterns can be simple strings (words, digits, etc.) or they can be . When the case finds a pattern that matches the string, it executes one or more commands.
Here's an example. It tests yourenvironment variable. If you're using a vt100 or tk4023 terminal, it runs a command to send some characters to your terminal. If you aren't on either of those, it prints an error and quits:
Here are more details about how this works.
The statement compares the string between the words
If the first pattern doesn't match, the shell tries the next
case - here,
As above, a match runs the command and jumps to the
The next pattern is the wildcard
You can use as many patterns as you want to. The first one that matches is used. It's okay if none of them match. The style doesn't matter much. Pick one that's readable and be consistent.