How to use variables or functions that are defined after the command.
Variable
#!/bin/bash
echo Hello \"$who\"
who=\"World\"
Variables and functions always have to be defined before use. This is because function definitions are actually commands that assign the name in the current context, and not like in C where they merely provide an implementation for a name.
You can instead use control flow to ensure that the definitions execute before your code, regardless of their relative layout in the file:
main() {
echo "Hello $var"
}
var="world"
main