title: Is it possible to make a bash shell script interact with another command line program?
body: <p>I am using a interactive command line program in a Linux terminal running the bash shell. I have a definite sequence of command that I input to the shell program. The program writes its output to standard output. One of these commands is a 'save' command, that writes the output of the previous command that was run, to a file to disk. </p>
  
  <p>A typical cycle is:</p>
  
  <pre><code>$prog
  $$cmdx
  $$&lt;some output&gt;
  $$save &lt;filename&gt;
  $$cmdy
  $$&lt;again, some output&gt;
  $$save &lt;filename&gt;
  $$q
  $&lt;back to bash shell&gt;
  </code></pre>
  
  <ul>
  <li><strong>$</strong> is the bash prompt</li>
  <li><strong>$$</strong> is the program's prompt</li>
  <li><em>q</em> is the quit command for <em>prog</em></li>
  <li><em>prog</em> is such that it appends the output of the previous command to <em>filename</em></li>
  </ul>
  
  <p>How can I automate this process? I would like to write a shell script that can start this program, and cycle through the steps, feeding it the commands one by one and, and then quitting. I hope the <em>save</em> command works correctly.</p>