Functions
Appearance
General
- When a function is invoked the positional parameters to the script are replaced by the params to the function. When the function finishes, they are restored
- declare local variables to the function using the local keyword
- functions can access shell variables that are part of the global scope
- in the absence of specifying a return value, a function returns the exit status of the last command executed
Syntax
function_name () {
statements
}
Examples
- Simple example
douche() {
echo "You are a douche"
}
echo "script starting"
douche
echo "script ending"