Function: functions, libraries, and code reuse are easy to centrally manage. The purpose of code reuse is to complete structured programming. Function-defined statements are not executed, but are loaded into the memory. They can be called multiple times in the same shell process and can be passed when called, it will be executed during the call.
Two Methods for defining functions
Function_name (){
... Nand
... CMD
}
Function fuction_name {
... CMD
... CMD
}
* ** Functions can be nested and called by yourself!
* ** Function location parameters
Format of the called Function
Function_name arg1 arg2...
The function accepts the parameter and passes the parameter to the function. when calling the function, you can directly pass it to the function. In the function body, arg1 is $1, and arg2 is $2, and so on.
Exit status of the function: Generally the exit status of the last command in the function body;
Exit status of the custom function: return [N]; this command exits the function, does not execute subsequent commands, and exits with the specified status value [N.
Function execution result: You can use echo or printf statement to print the result (related variables )!
The range of the variable value specified in the function: the remaining script content! You can use the local command to clearly declare that the scope of the variable is the function body!
This article comes from the blog "Let me be more hungry", please be sure to keep this source http://ufirst.blog.51cto.com/7628670/1432614