The case name in the shell under Linux is similar to the switch in C + +, but the cases in the shell are more powerful and complex.
1, strong mainly reflected in: Shell in case the keyword can be a string type, and each item can contain regular expressions.
2, the complexity is mainly reflected in: the shell of each item in the case after three choices: Break (regular break), unconditional follow up (unconditional continue) and conditional follow up (conditional continue).
The main point of this article is the 2nd above.
The unconditional continuation of the case and conditional continuation are features that are available in the Bash 4.1.x and later versions.
Execute the following command to view the version of your current bash
Echo $BASH _version
Regular break is added at the back of each item;;
To continue unconditionally is to add;& after each item
Conditionally continue to be added after each item;; &
Test code
#!/bin/bashecho "Test No.1 ..." case "1" in 1) echo ' 1 '; & 2) echo ' 2 ';; 3) echo ' 3 ';; ?) echo '? ';; *) echo ' * ';; Esacecho "Test No.2 ..." case "1" in 1) echo ' 1 '; 2) echo ' 2 ';; & 3) echo ' 3 ';; ?) echo '? ';; *) echo ' * ';; Esacecho "Test No.3 ..." case "1" in 1) echo ' 1 ';& 2 "echo ' 2 ';; 3) echo ' 3 ';; ?) echo '? ';; *) echo ' * ';; Esacecho "Test No.4 ..." case "1" in 1) echo ' 1 '; 2) echo ' 2 ';& 3) echo ' 3 '; ?) echo '? ';; *) echo ' * ';; Esac
Test results:
Test No.1 ... 1? Test No.2 ... 1Test No.3 ... 12Test No.4 ... 1