You are used to other languages, such as Perl, which allow you to call a function in a section of your code that comes before the actual function definition.
Shell scripts are read and executed in a top-to-bottom linear way, so you must define any functions before you use them.
Some other languages, such as Perl, go through intermediate steps
during which the entire script is parsed as a unit. That allows you to
write your code so that main()
is at
the top, and function (or subroutines) are defined later. By contrast, a
shell script is read into memory and then executed one line at a time,
so you can’t use a function before you define it.
18.224.30.19