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 worked correctly. So it seems to me as though my version of ed, which is the one from MacOS 10.12, has problems if commands appear at inconvenient times.
Why doesn't ed simply avoid reading stdin until it's ready to process whatever commands it gets? Or am I misinterpreting the situation?
The error message
?isn't too helpful. In an interactive session I could typehafterwards 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 slowly? What versions of ed would be affected?
gnu ed. It only happened when piping (|) the commands toed, it never happened when using here-docs or here-strings so my advice is to try using a here-doc to pass the commands toed(e.g.ed -s somefile.sql <<IN...)