If statement
The judging condition is wrapped up in []
If [$a > $b]
Then
Echo ' a > B '
elif [$a < $b]
Then
Echo ' A < b '
Else
Echo ' A==b '
Fi
for Statement
Iterating through an array
For arr in ${array[*]}
Do
Echo ${arr}
Done
while Statement
If the value of the variable is less than 5, then the value of the variable plus 1 output
Var=1
While [$var –lt 5]
Do
var= ' Expr $var +1 '
Echo $var
Done
Defining functions
Some functions are reusable, can be encapsulated into functions, the function is defined in the following format:
Function_name () {
List of commands
[Return value]
}
Calling functions
The pass-through parameter is optional. If you need to pass a parameter, simply add the argument value after the called function
Function_name 10 20
Get the value of a parameter in a function
When defining a function, the arguments in parentheses after the function name are not written, to get the parameters passed in the function using $
Get first parameter
$ get second argument
Get the return value of a function
$? is to get the result returned by the previous instruction, then to get the value returned by the function, just write the $ on the line below the statement that called the function.
Shell Process Control