Hi Artyom,

Artyom Bologov wrote:
ged seems to just skip the erroring command and proceed with the script.

It depends on how you feed the script to GNU ed:

http://www.gnu.org/software/ed/manual/ed_manual.html#Diagnostics
When an error occurs, if ed's standard input is a regular file or here document, then it exits, otherwise it prints a '?' and returns to command mode.

Which is a valid behavior too, but slightly more dangerous in the context
of scripting text modifications.

Only if you do not check the exit status of ed.

Any ideas for how to address that?

You may use
  ed -s file.txt < script
instead of
  cat script | ed -s file.txt

Piped scripts count as interactive for GNU ed and do not force it to exit on the first error. In the long term, maybe GNU ed could align its definition of "interactive" with that of POSIX:

https://pubs.opengroup.org/onlinepubs/9799919799/utilities/ed.html
CONSEQUENCES OF ERRORS
When an error in the input script is encountered, or when an error is detected that is a consequence of the data (not) present in the file or due to an external condition such as a read or write error:

* If the standard input is a terminal device file, all input shall be flushed, and a new command read.

* If the standard input is not a terminal device file, ed shall behave as described under CONSEQUENCES OF ERRORS in 1.4 Utility Description Defaults.


Best regards,
Antonio.

Reply via email to