Change the previous code
1. Infer if it is hello, assuming yes. It shows "Hello, how is it?" ;
2. Assume that no number of parameters is added or not. To prompt the user must use the method of the number of instructions;
3. Assuming that the increased number of references is not a Hello, the user is reminded to use only hello as the parameter.
What is interesting to detect is the more common port 21, 22, 25 and 80 o'clock, then how do I go through the netstat to test if my host has to open these four basic network service ports? The keyword of each service is followed by a colon ":". So it can be measured by capturing something like ": 80".
Use case ... Esac inference
Case $Variable nameinch <==keyword is case, there are variables before the rich font size"First variable content") <== the contents of each variable are suggested to be enclosed in double-quotes. Keyword is the parenthesis)Program Segment;; <== Each category ends with two consecutive semicolons. "Second variable content")Program Segment;;*) <== The last variable content will use * to represent all other valuesOther programs that do not include the contents of the first variable and the contents of the second variable exit 1;;Esac <== Finally the case end! "Turn to write" think about it.
|
It is important to note that this syntax begins with the case (the meaning of the actual cases), and the end is naturally written in the English language in turn! Just become ESAC! It won't be very hard to recite! In addition, two semicolons are required at the end of each program section of the variable content (;;) to represent the end of the program paragraph, which is very important! Why should there be * this variable content at the end? This is due to. Assume that the user is not the input variable content one or two o'clock, we can inform the user of the relevant information Ah!
In general, use the "case $ variable in" syntax. One of the "$ variables" is roughly two ways to get there:
Direct release: As mentioned above, the use of "script.sh variable" way to directly give the contents of this variable, which is the/etc/init.d folder under the design of most programs.
Interactive: Read this command to let the user enter the contents of the variable.
Shell Scripts-Conditional statements, case statements, function functions