Skip to main content
added 18 characters in body
Source Link
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 IFS= read -r line
      do
        echoprintf '%s\n' "$line" >/dev/tty
        echoprintf '%s\n' "$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.

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 IFS= read -r 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.

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 IFS= read -r line
      do
        printf '%s\n' "$line" >/dev/tty
        printf '%s\n' "$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.

make read read raw lines, thanks to don_crissti
Source Link
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 IFS= read -r 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.

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.

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 IFS= read -r 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.

added 265 characters in body
Source Link
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 linesa 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.

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 lines to 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

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.

Source Link
Mark Plotnick
  • 26k
  • 3
  • 68
  • 82
Loading