shell programming branch of the case statement
Enterprise
2019-12-07 23:43:36
views: null
shell programming branch of the case statement
case and if the multi-branch statement branch statement is very similar.
if multiple branching statements generally used where there is (the interval range); for example: 0-100.
if necessary to determine a plurality of different conditions.
If a case statement branches to a fixed value which matches; or in the presence of multiple values of a variable, required command sequence performs different value for each of them.
Analyzing case but different values of a variable.
case model:
Implementation process:
First, using the "variable value" is compared with the pattern 1, if the value identical to Run Mode 1 1 sequence, until she met ";;" esac after jumping to the end.
If the pattern does not match the 1, 2 continue compared with the next mode, if the same sequence of mode 2 Run 2, met know ";;" to jump to the end esac. If you still can not find any matching value, then the implementation of "*)" the default mode after the default command sequence, until she met the end of esac.
When using the case branching statements, there are a few points to note:
Tail 1.case word line must be 'in', each pattern must end with a right parenthesis ')'.
2. Double semicolons ";;", indicating the end of a command sequence.
3. The pattern string, can use the "[]" represents a continuous range, such as: [0-9]; symbols can also use the vertical bar "|" (or represented), such as: a | b.
4. Final " )" denotes the default mode, in which " " corresponds to a wildcard.
Origin blog.51cto.com/14557584/2456923