Change the previous code
1. Infer if it is hello, and if so, it shows "Hello, how is it?" ;
2. Assume that no number of parameters is added or not. The method that prompts the user to be required to use the number of parameters.
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? Since the keyword of each service is followed by a colon ":", it is possible to detect 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, and keyword are parentheses .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 values do not include the contents of the first variable with the contents of the second variable execution segment exit 1;; esac <== finally the case end! "Turn to write" Think about it!
|
It's important to note that. This syntax begins with the case (the meaning of the actual cases). The end of the course is to write the English case in reverse. It becomes ESAC. It won't be very hard to recite!
Other than that. Each variable has a two semicolon (;) 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 the assumption that the consumer is not the input variable content one or two o'clock. We can tell the user about the information.
Generally speaking. Use the "Case $ variable in" syntax. One of the "$ variables" is roughly two ways to get there:
Direct release: As mentioned above. Use the "script.sh variable" method to directly give the contents of this variable. This is also the way most programs are designed under the/etc/init.d folder.
Interactive: Read this command to let the user enter the contents of the variable.
Shell Scripts-Conditional statements, case statements, function functions