Functions: Code snippets that implement standalone functionality
function is only executed when called
Syntax One:
function f_name{
function body
}
Syntax Two:
F_name () {
function body
}
The return value of the function:
Default function return value: Function execution state return value, default is the state value executed by the last command in the script, no actual use
Custom function return value: return [0-255]
0: Success
Non 0: Failed
function Example
Loop control:
Continue: End this cycle in advance and go directly to the next cycle.
For example, the code will loop five times after execution is complete. In the third cycle, the continue is directly out of the third cycle, the fourth cycle of the body.
Break: Terminates the loop body directly, i.e. jumps out of the loop.
For example, the code will loop five times after execution is complete. Break was started in the third cycle. It jumps out of the loop body, and the No. 345 cycle is not executed.
A special use of the while loop: iterates through the lines of a file, reading each line of the file one at a time, and then assigning it to variable.
While Read Variable;do
Loop body
Done </path/from/somefile
While special usage example:
Special usage for the FOR loop:
For (control variable initialization; conditional judgment expression; control variable correction statement);d O
Loop body
Done
For Loop example
function and cyclic control of Linux--shell programming