[dev] [sbase] sed 'd' command after 'r' or 'a' (POSIX interpretation question)

From: Michael Forney <mforney_AT_mforney.org>
Date: Fri, 17 Jan 2020 02:05:26 -0800


I recently ran into a package (dialog), which uses the following sed
script to generate its dlg_config.h header:

/_AT_DEFS@/r conftest.frag

The intention is to replace _AT_DEFS@ in the header template with the
contents of a file. However, sbase sed skips writing the contents of
the file since the pattern space gets deleted later on.

All the other implementations I looked at *do* insert the contents of the file.

Here's what POSIX says on the matter:

> The a and r commands schedule text for later output. The text specified
> for the a command, and the contents of the file specified for the r
> command, shall be written to standard output just before the next
> attempt to fetch a line of input when executing the N or n commands, or
> when reaching the end of the script. If written when reaching the end
> of the script, and the −n option was not specified, the text shall be
> written after copying the pattern space to standard output. The
> contents of the file specified for the r command shall be as of the
> time the output is written, not the time the r command is applied. The
> text shall be output in the order in which the a and r commands were
> applied to the input.


> [2addr]d Delete the pattern space and start the next cycle.

Only the cases where n or N are used or the end of the script is
reached are described. So I guess the question is whether or not
"start the next cycle" means "jump to the end of the script". It's not
really clear to me from the POSIX description.

Does anyone have any insight on this issue? I'm thinking we should
probably change sbase sed to match the other implementations.
Received on Fri Jan 17 2020 - 11:05:26 CET

This archive was generated by hypermail 2.3.0 : Fri Jan 17 2020 - 14:24:07 CET