|
Case statements allow you to test a string using a series of patterns, executing only the commands for the matching pattern. The general format of the case statement is: case string in pattern_1) commands ;; pattern_2) commands ;; pattern_3) commands ;; ... esac The patterns you can use are:
An example case statement is: #!/bin/bash name=John case $name in john|John) echo Welcome $name ;; sam|Sam) echo Hello $name ;; *) echo You're not invited ;; esac The * is used for the last case, to handle all the conditions not listed specifically in previous sections of the case statement. Any string that doesn't contain John or Sam's name matches the last case. |
|