title: Easily creating a bash script in python
body: <p>I'm looking to write some tests that will create and execute a bash script. Bash itself has a nice way to do this:</p>
  
  <pre><code> % cat &gt; run.sh &lt;&lt; EOF
   &gt; echo "I ran this"
   &gt; EOF
   % . run.sh
   I ran this
  </code></pre>
  
  <p>In Python I can do this:</p>
  
  <pre><code> with open ('run.sh', 'w') as rsh:
      rsh.write('echo "I ran this"\n')
   -- etc ---
  </code></pre>
  
  <p>This is fine for a short script in Python, but I'm wondering if there is some technique I don't know about that let's me do something like what I can do in bash.</p>