title: Bash EOF has unexpected behavior
body: <p>I was using a quick and dirty BASH script to automate a CF partitioning process.<br>
  This worked well until I wanted to add to it.</p>
  
  <p>Basically, I have a script which partitions a compact flash as such:</p>
  
  <pre><code>CMD=.fdisk
  DEV=/dev/sdc
  
  echo "Calculating partition sizes..."
  P1SIZE=+1100M
  P2SIZE=+1200M
  
  echo "Creating instruction file..."
  PT1="n p 1\n $P1SIZE"
  PT2="n p 2\n $P2SIZE"
  END="a 1 w EOF\n"
  
  [ -e $CMD ] &amp;&amp; rm -rf $CMD
  
  for i in $PT1 $PT2 $END; do echo -e $i &gt;&gt; $CMD; done
  
  echo "Creating partitions..."
  fdisk $DEV &lt;&lt; EOF &lt; $CMD
  [ -e $CMD ] &amp;&amp; rm -f $CMD
  </code></pre>
  
  <p>The idea is that in the future the file represented by '$CMD' will be created automatically by an external tool with the proper start and end values.  Right now I simply accept the default start and provide a size.</p>
  
  <p>This worked quite well until I wanted to incorporate a few additional steps to my script.  But I got into problems when I noticed weird behaviors.</p>
  
  <p>The first is that if I add the code above inside a function, I will keep getting a script error:</p>
  
  <pre><code>line XX: syntax error: unexpected end of file
  </code></pre>
  
  <p>Also, I realized that any additional code after the 'fdisk' command will not execute and the script seems to simply terminate (without errors, $? = 0).</p>
  
  <p>Does anyone know why the function doesn't work and the script terminates?</p>