Functions used in Bash Scripts.

Since scripts a read from top to bottom functions must be declared in lines above where they are called.

The return value of the most recently run function are saved in the ? variable and can be accessed by $?.

Declaration

Functions can be declared with the following two choices of syntax:

function name {
    <commands>
    return <value>
}

or

name() {
    <commands>
    return <value>
}

where return <value> can be omitted for void functions.

Calling

Function can be called by itself or with arguments with the same syntax as a Bash command in the command-line:

<function name> <variable1> <variable2>