Forward declaration in shell scripts are most elegantly handled by including a main function up-top that handles the execution order of the script. Then anywhere else in the script, preferably last, simply call: main "$@"
From http://stackoverflow.com/questions/13588457/forward-declarations-in-bash/13588485
#!/bin/bash
main() {
foo
bar
baz
}
foo() {
}
bar() {
}
baz() {
}
main "$@"