function:
Function Description function
To avoid duplication of code used, we generally by the function block write, a block of code which is used to implement certain functions, this feature later in the code, the call will be repeated;Function syntax
{check_cpu functionCAT / proc / cpuinfo
}
LS / etc /
check_cpu [not call function, the body of the function commands are not executed; where to invoke the function execution command body] where
fun_name () {
function body
$ 2 ... $ 10 $. 1
}
fun_name 2. 3. 1
: WQ
function.sh. 4. 5. 6. 7. 9 10. 8 12 is 13 is 14. 11
function body
$ 2 ... $ 10 $. 1
}
fun_name 2. 3. 1
: WQ
function.sh. 4. 5. 6. 7. 9 10. 8 12 is 13 is 14. 11
Function return value
return
When the function is specified in the judgment statement, we default to return a wrong result, but recently a command indeed correct, this time, we need to return the one we need error status code by return;end of the function, we need specify a return return code is correct; if used in a loop statement, return will be out of the loop;
Function accepts parameters
Function variablesand common commands, like
just need to pay attention to, when the function accepts parameters, does not use an external mass participation, but to prevail within the parameters of the script,
Function variables
Local variablelocal variable name = xxx
local variables inside this function takes effect only on
local variables
variables inside the script
environment variables
to take effect in the entire bash Linux system
Script Execution
bash way to perform - # / bin / bash!variable bash script executed as defined in the sub-shell of the current shell;
the full path or relative path way to perform; - shall be authorized to execute permissions;
Source script file or a script file
when the source of the script is performed in this manner, the value of the internal variable defined in the current of the shell;