I. Overview of CASE statements
Use case statements to rewrite if multiple branches to make the script structure clearer and more hierarchical
Perform different command sequences for different values of variables
The case statement is structured as follows:
Case Variable value in
Mode 1)
Command sequence 1
;;
Mode 2)
Command Sequence 2
;;
*)
Default command sequence
Esac
1 #!/bin/bash2Read-p"Please enter a character:"Key3Case"$key" inch4[a-z]| [A-z])#if the variable $key in 26 uppercase and lowercase letters5Echo"you entered the letter"6 ;;7[0-9])#if the variable $key in the number 0 to 98Echo"you have entered a number"9 ;;Ten*) OneEcho"you have entered a different function key" AEsac
Second, the case statement written by the program control script
The case statement is widely used to write program control scripts, with Chkconfig for controlling switches. This knowledge please refer to http://www.cnblogs.com/mangood/p/6033044.html
Third, Shell functions
The command sequence is written in a format so that it is easy to reuse the sequence of commands, and we call this sequence of commands as functions
(1) Definition of function: where [function] can be written and not written
[Function] Function name () {
Command sequence
[Return x]
}
(2) calling a function
function name [parameter 1] [parameter 2]
Case and function of shell programming