title: Bash - writing function definition in script after first call (as a GOTO/jump problematics)
body: <p>I basically want to write me a bash script, where I'd generate a couple of big files using <a href="http://tldp.org/LDP/abs/html/here-docs.html" rel="noreferrer">heredoc</a>; and then run some commands using those files. </p>
  
  <p>It is understood that (obviously) the heredoc files need to be generated before the commands run - however, what irritates me in that arrangement, is that I must also write the 'heredoc' statements code, <em>before</em> I write the command code. </p>
  
  <p>So I thought I'd write the heredoc statements in a function - but still the same problem here: <a href="http://tldp.org/LDP/abs/html/functions.html" rel="noreferrer">Chapter 24. Functions</a> says: </p>
  
  <blockquote>
    <p>The function definition must precede the first call to it. There is no method of "declaring" the function, as, for example, in C.</p>
  </blockquote>
  
  <p>Indeed, it is so:</p>
  
  <pre><code>$ cat &gt; test.sh &lt;&lt;EOF
  testo
  
  function testo {
    echo "a"
  }
  EOF
  
  $ bash test.sh 
  test.sh: line 1: testo: command not found
  </code></pre>
  
  <p>Then I thought maybe I could place some labels and jump around with <code>GOTO</code>, as in (pseudocode):</p>
  
  <pre><code>$ cat &gt; test.sh &lt;&lt;EOF
  goto :FUNCLABEL
  
  :MAIN
  testo
  
  goto :EXIT
  
  :FUNCLABEL
  function testo {
    echo "a"
  }
  goto MAIN
  
  :EXIT
  </code></pre>
  
  <p>... but it turns out <a href="http://www.linuxquestions.org/questions/programming-9/bash-goto-384407/" rel="noreferrer">BASH goto</a> doesn't exist either.</p>
  
  <p>My only goal is that - I want to first write the "core" of the script file, which is some five-six commands; and only <em>then</em> write the heredoc statements in the script file (which may have hundreds of lines); having the heredocs first really makes reading the code difficult for me. Is there any way to achieve that? </p>