Normally in Bourne Shell and perhaps in most of Korn Shell implementations, functions have to be defined BEFORE all the coding using them.
You can also create a your own "function library" to recall in your script in such way
. /path_to_your_function_library/your_function_library
... blah
.... blah
..... blah
Keep in mind shell functions doesn't return a value in their name, they behave more like the GOSUB in the old BASIC.
Shell functions can modify your script variable or return an output, they can use INPUT parameters like
MyFunction () {
if [ $1 = "goofie" ];then blah blah blah;fi
}
#
# main code
#
you can use some trick to return a value inside a variable you like and whose name can change time by time like:
MyFunction () {
eval ${2}=$1'-mouse'
}
#
# main code
#
MyFunction "mickey" "goofie"
This Function will insert in the variable goofie the value of $1 (mickey) followed by a "-minnie"
As you can see the variable "goofie" is not represented like $goofie, because in that case the shell will set to "mickey-mouse"a variable whose name is contained in $goofie