First, conditional statements
- Simple conditions
if Then # When the condition is established, the content is executed;fi If the reverse is written, the meaning offiif
Complex conditions
if Then # When condition is established, execute content;else # When condition is established, the content is executed;fi
if Then # When Condition1 is established, the content is executed;elifthen # When the Condition2 is established, the content is executed; Else # When Condition1 and Condition2 are not established, the content is executed;fi
Second, the circular statement
- for
for var in Con1 con2 Con3 ... do # Execute content done
note : Con1,con2,con3 is a list of strings, separated by spaces
for var in {min... Max} do # Execute content done
note : Min is called decimal, Max is a larger number, step is 1.
for (initial value; limit value; step) do done
- While
while [Condition] # when the condition condition is established, loop until the condition is not set to stop do # execution content
Done
UNTIL
until [Condition] # And while in contrast, when the condition condition is true, the loop is terminated, or the program segment of the loop continues to do the content
Done
III. SELECT statements
- case
case $ variable in " first variable content " second variable contents ) # execute content;; *) # The last variable content will be used * to represent all other values, but not the contents of the first variable with the contents of the second variable run segment # execution content;; esac # The end of the case ending in an anti-write
- SELECT
Select inch con1 con2 con3 # automatically lists Con1,con2,con3 's selection menu do #执行内容break # Select itself is a loop, Break is when you choose to jump out of the loop done
Note: Select is an extension of bash, automatic read input selection sequence, and pass selection to variable
Basic syntax structure summary of Shell programming basics