title: Programmatically send commands to an interactive REPL from Bash?
body: <p>Is it possible to programmatically enter some repl (say <code>mongo</code>), and programmatically interact with it? That is to say, can you do this programmatically:</p>
  
  <pre><code>$ mongo
  MongoDB shell version: 2.4.8
  connecting to: test
  &gt; db.collections
  test.collections
  &gt; exit
  bye
  </code></pre>
  
  <p>All that does is:</p>
  
  <ol>
  <li>Login to the REPL with the <code>mongo</code> command. I know it's possible to do this somehow, I have seen it done to <a href="http://maxogden.com/node-repl.html" rel="nofollow">create interactive REPL's in the Node.js world</a>. It would be helpful to know how to do this in bash directly.</li>
  <li>Once logged in, I typed <code>db.collections</code>, just exploring the REPL. This SO question is asking, can you do <em>this</em> programmatically? Like can you perhaps (a) create a child process/REPL from a bash script, and then (b) send it arbitrary messages like this <code>db.collections</code>, which it evaluates. (And can you get the response/output back).</li>
  <li>Programmatically log out of the REPL.</li>
  </ol>
  
  <p>Is this possible?</p>