Modify the previous Code
1. Determine if it is hello, and if so, show "Hello, how is it?" ;
2. If no parameters are added, the user is prompted to use the parameter release method;
3. If the added parameter is not hello, the user is reminded that only the Hello parameter can be used.
Interesting to detect is the more common port 21, 22, 25 and 80 o'clock, then how can I go through the netstat to detect whether my host has opened these four major network service ports? Since the keyword for each service is followed by the colon ":", it can be detected by retrieving something like ": 80"!
Use case ... Esac to judge
Case $Variable nameinch <== keyword is case, there are variables before the rich font size"First variable content") <== the contents of each variable are suggested in double quotation marks, and the keyword is a parenthesis.Program Segment;; <== use two consecutive semicolons to handle each category end! "Second variable content")Program Segment;;*) <== The last variable content will use * to represent all other valuesOther programs that do not contain the contents of the first variable and the contents of the second variable run a segment exit 1;;Esac <== The final 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 hard to recite! In addition, each variable content of the program section will need two semicolon (;;) to represent the end of the program paragraph, which is very important! Why does it need to have * this variable content at the end? This is because if 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, in the syntax of "case $ variable in", the "$ variable" is roughly two ways to get it:
Direct release: As mentioned above, using the "script.sh variable" way to directly give the contents of this variable, which is also in the/ETC/INIT.D directory under the design of most programs.
Interactive: Read this command to let the user enter the contents of the variable.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Shell Scripts-Conditional statements, case statements, function functions