Article Directory
Shell function definition
Definition: write the command sequence together in a format to facilitate repeated use of the command sequence
Shell function format
Format one
function 函数名 {
命令序列
}
Format two
函数名() {
命令序列
}
Shell function return value
return means to exit the function and return a value, the value can be displayed by the $? variable in the script
Usage principle :
take the return value at the end of the function, because the $? variable only returns the exit status code of the last command executed. The
exit status code must be 0~255, and the value beyond that is divided by 256 and the remainder
Shell function passing parameters
Shell function variable scope
Functions in Shell scripts are only valid in the current Shell environment
. Variables in Shell scripts are globally effective by default.
Limit variables to functions. Use local commands.
Recursion
Factorial
recursive lookup
Create function library
Put commonly used functions into a separate library script, so that when the script is in use, you can directly call the functions in this library