wrapper script design for gnu ed text editor i/o

view story

http://www.unix.com – Hi. I'm having trouble writing a wrapper script for the command line text editor gnu ed. I want to be able to run the following algorithm on ed: 1. Display, on stdout, a command which I intend to feed into ed (before I actually feed it to ed). 2. Actually feed the command into ed's stdin. 3. Wait until ed finishes displaying whatever stderr and stdout it must, redirecting all (stderr and stdout) to stdout. 4. End if the command is q or Q. 5. Otherwise, go back to step 1. I want to achieve this, in order to be able to automate ed (or any other command-line utility for that matter) through ba (HowTos)