Get the App
SLTechnology News&Howtos  ›  Servers  › 

Case Branch statement of shell programming

Shulou Source: shulou.com Published: 2022-06-03 00:50:07 09月22日 Update

The case branch statement of shell programming case branch statement is very similar to the multi-branch statement of if. If multi-branch statements are generally used where there is (interval range); for example, between 0 and 100. If needs to determine several different conditions. The branch statement of case is used if it matches to a fixed value, or if a variable has multiple values, you need to execute a different sequence of commands for each of these values. Case simply judges the different values of a variable. Mode of case:

Execution process: first use "variable value" to compare with mode 1, and if the value is the same, execute the command sequence 1 of mode 1 until you encounter ";;" and then jump to the end of esac. If it does not match mode 1, it continues to compare with the next mode 2, and if it is the same, execute the command sequence 2 of mode 2 until you meet ";" and jump to the end of esac. If no matching value is found, the default command sequence after the "*)" default mode is executed until the end of the esac encounter. When using case branch statements, there are several points to note: the 1.case line must end with the word 'in', every pattern must end with a closing parenthesis'. two。 The double semicolon ";" indicates the end of the command sequence. 3. In a pattern string, you can use "[]" to indicate a contiguous range, such as [0-9], or the vertical bar symbol "|" (or), such as: a | b. 4. The last ")", which represents the default mode, where "" is equivalent to a wildcard.

Tags: Patterns branches statements commands sequences different same variables ranges programming similarity between semicolons intervals words just places multiple characters strings Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Xiaomi Huawei MySQL NVidia