title: How to export part of the bash script as external file
body: <p>I write a script that manages creation of creation of lxc virtual container. It consists of a part that is executed on the host, and part that is executed by the container (a virtual guest). It would be more elegant if I could write both scripts in on file, and extract the second script from it when it is needed (and subsequently run on the container).</p>
  
  <p>I vaguely remember, that there is a way to do that in bash, but I don't know how to find the name of this feature and how to use it. </p>
  
  <p>I need something like this:</p>
  
  <pre><code>#/bin/bash
  
  # here are commands that are to
  # be executed by the host
  
  &lt;declare start of the code chunk that will be exported to file&gt;
  
      # here go commands that 
      # need to be invoked by the guest
  
  &lt;end of code chunk. Paste the above code into the /var/lib/lxc/&lt;mycontainer&gt;/rootfs/tmp/second-stage.sh&gt;
  
  sudo lxc-attach -n &lt;container name&gt; /tmp/second-stage.sh
  </code></pre>