In this context I've encountered a situation where ed file < script would print ? and exit with error 2, while typing or pasting the commands from script one at a time worked fine. Even having a shell process pass the file through one line at a time with a sleep in between did work. So it seems to me as though my version of ed, which is the one from macOS 10.12, were having problems if commands appear at inconvenient times.Why doesn't ed simply avoid reading stdin until it's ready to process whatever comands it gets? Or am I misinterpreting the situation?The error message ? isn't too helpful. In an interactive session I could type h afterwards to get an error message, according to the man page. But with input from a non-TTY it exits immediately. Is there some way to get at the error message in this case, too?Is this a known issue? If so, are there any suggested workarounds instead of passing the commands in real slow? What versions of ed would be affected?
Ed script only works if typed slowly
scripting;stdin;ed