Skip to main content
2 of 4
added 265 characters in body
Mark Plotnick
  • 26k
  • 3
  • 68
  • 82

It sounds like you want to simulate an interactive terminal session, in which the user types a command, waits for a response (or, given that the target is ed, sometimes waits for a response), then types another command, etc. You could write an expect script to do this, but it may be good enough to just send a line at a time to both the terminal and the target process, with a brief pause between each line.

    $ while read line
      do
        echo "$line" >/dev/tty
        echo "$line"
        sleep 0.5
      done < helloworld | ed
a
hello
world
.
,n
1   hello
2   world
,s,o,O,g
,n
1   hellO
2   wOrld
Q

To better distinguish input from output, you could add color or other highlighting to the
echo "$line" >/dev/tty line, or, in this particular case, enable the prompt character in ed (the P command) so that a * will show up in front of each ed command.

Mark Plotnick
  • 26k
  • 3
  • 68
  • 82