Case statement and scripting Options Advanced Detail
the control flow in the process-oriented programming language (that is, the statements in the program) is executed sequentially by default.
Control structure of programming language there are three categories:
1, sequential structure
2, select structure
(1) If statement
If statement for a single branch
Format: If Condition1;then
Expression
...
Fi
If statement for two branches
Format: If Condition1;then
Expression
...
Else
Expression
...
Fi
If statements for multiple branches
Format: If Condition1;then
Expression
...
Elif Condition2;then
Expression
...
Else
Expression
...
Fi
A multi-branched if statement is less efficient to perform because it is a condition that is then compared to a condition.
(2) Case statement
We choose a structure with a second statement, that is, our case statement, more explicit structure than the multi-branch if statement, simpler to use, more efficient choice of structure statements.
Usage format: case (keyword) SWITCH (variable, which refers to the value of a variable, not the variable itself) in
And the value of our variable will have the following several cases
Value 1) This is not the condition, but the value of the variable, the first value of the variable
Expression
...;;( None of the options can end with a double semicolon)
Value 2)-the second type
Expression
...;;
...
*)
Expression
...
Esac
Value can have more than one
Exercise: Write a script that asks
Let the user type the content from the keyboard and then use our script to determine what the user typed and display it
Type a number to display a number, type a lowercase letter to display lowercase letters, and type uppercase letters to show uppercase
Script content:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/85/29/wKioL1ebL7mgZa3XAABDGHZIqAc834.png "title=" w~j8_) @9[zkqy$j~ccwun8k.png "alt=" Wkiol1ebl7mgza3xaabdghziqac834.png "/>
Script Execution Results:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/85/29/wKiom1ebL9DyYyrxAAAYOxuQ1eU309.png "title=" ~ Bqrl4i4em85jccfmscqz_l.png "alt=" Wkiom1ebl9dyyyrxaaayoxuq1eu309.png "/>
Exercise: Write a script that asks
The script only receives one of these four parameters, Start,stop,restart,status
And then display the corresponding content
Script content:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/85/29/wKiom1ebMSjzu5f2AABBnY3g95Q535.png "title=" O) q}l~ FS6) @ @Z88SLD) egpy.png "alt=" Wkiom1ebmsjzu5f2aabbny3g95q535.png "/>
Script Execution Results:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/85/29/wKioL1ebMTfSZDldAAAzU435f20579.png "title=" R61ale }P_4O6T) 6z97hkn (f.png "alt=" Wkiol1ebmtfszdldaaazu435f20579.png "/>
Exercise: Write a script that asks
Can receive the options and parameters, and then get each option and parameters, and can be based on options and parameters to make a specific operation
Like->boke3.sh--add tom,jerry--del tom,blair-v|--verbose-h|--help
Script content:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/85/29/wKioL1ebOMDBbETdAACzvXN7gOs555.png "title=" _ 4zzfvuimwm~q}bd@r ' {z9m.png ' alt= "Wkiol1ebomdbbetdaaczvxn7gos555.png"/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/29/wKiom1ebONmQg6HYAACLVWZ0Bpg884.png "title=" Rg{_ " am{_tyk1t@51wl[' Km.png "alt=" Wkiom1ebonmqg6hyaaclvwz0bpg884.png "/>
Script Execution Results:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/85/29/wKioL1ebOPOTrJBxAAAzCFpQTGg367.png "title=" C%g_ 1lf~p}6$}pjbhboiypk.png "alt=" Wkiol1ebopotrjbxaaazcfpqtgg367.png "/>
Exercise: Write a script that asks
The script is named boke4.sh
The script is formatted as SHOWLOGGED.SH-V-c-h|--help
Where-h option can only be used alone to display help information;
The-C option displays the number of all users logged on on the current system, and if the-v option is used at the same time, displays both the number of simultaneous users and information about the logged-on user.
Script content:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/85/2A/wKioL1ebSS_BwpqtAADBo5A3jRQ420.png "title=" 9% 9D6K5SGXV_CT) ymneaiex.png "alt=" Wkiol1ebss_bwpqtaadbo5a3jrq420.png "/>
Script Execution Results:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/85/2A/wKiom1ebSUbQ4cL0AABOx9ipH24026.png "title=" vfyzu{ 1VQE '}x1]6bdvbf}a.png "alt=" Wkiom1ebsubq4cl0aabox9iph24026.png "/>
3, Cycle structure
For statement
This article is from the "Novice Technical Documents" blog, please be sure to keep this source http://zhubo.blog.51cto.com/11395641/1831868
Bash Script programming case statements and scripting options advanced