Syntax structure of case:
Case to test item in style string 1] command area 1;;( Style string 2) command area 2;; Style string 3) command area 3;; *) command area;; Esac
- Command area, can be a single instruction or multi-line instruction, but the last command to be;; End.
- Styles are available as string and wildcard characters, and are case-sensitive by default.
- If the style serial has several strings to compare, use | Separated. Characters | There is a "or" meaning, that is, as long as one of them, even more successful.
- Style serial can be written as ' (style serial) ', or omit left parenthesis, write ' style serial '. Generally, it is more popular to use the following notation.
- Style *) is typically placed in the case where there is an area that captures all other situations that do not conform to the pattern.
- Finally, end the case syntax with ESAC. Esac is the inverse of case.
Example:
#!/bin/bashread ynamecase $yname Injack | John | Joe) echo ' Well ... ' echo ' Long time no see. ' echo "How does do";;( Mary | Mary) echo ' Nice to meet you ';; c*) echo ' Long time to see. ';; *) echo ' hi! ';; Esac
Shell Getting Started Tutorial: Process Control (4) Case condition judgment