Bug 279223

Summary: sed - "a\" command displays different results depending on use of -e option (closing new line)
Product: Base System Reporter: Eric <erichanskrs>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: New ---    
Severity: Affects Only Me CC: chris, ericvermetten
Priority: ---    
Version: 13.3-RELEASE   
Hardware: amd64   
OS: Any   

Description Eric 2024-05-22 16:11:57 UTC
test
Comment 1 Eric 2024-05-22 16:13:18 UTC
Using 13.3-RELEASE and "pkg install gsed" (version 4.9).

For the a\ command of sed(1), whether or not specifying the -e option, produces different results.
sed ' ... ' (without the -e option) seems to be in error.

	$ cat t
	1
	2
	$ cat sed-add.sh
	#!/bin/sh
	sed '/1/a\
	-new line-' <t

	printf "\n>> sed -e '... '\n"
	sed -e '/1/a\
	-new line-' <t
	$ sh sed-add.sh
	1
	-new line-2

	>> sed -e ' ... '
	1
	-new line-
	2

Using variants with double quotes, as in:
	sed "/1/a\\
	-new line-" <t
display the same differences.

gsed behaves as FreeBSD sed -e ' ... '

I couldn't find any specific POSIX guidance at:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html
but the behaviour of sed -e ' ... ' seems the correct one.
Comment 2 Eric Vermetten 2024-05-22 22:25:44 UTC
In addition to previous comment:

	sed '/1/a\
	-new line-
	' <t
results in:
	1
	-new line-
	2
as do all variations over:
- double double quotes vs single quotes, 
- sed vs gsed,
- option -e present vs not present.

Implicit description of its intended <EOL> behaviour, is mentioned in:
sed & awk, 2nd edition;  Arnold Robbin, Dale Dougherty
at the "Command Summary for sed":
"
a [address]a\
text
Append text following each line matched by address. If text goes over more
than one line, newlines must be "hidden" by preceding them with a
backslash. The text will be terminated by the first newline that is not hidden
in this way. The text is not available in the pattern space and subsequent
commands cannot be applied to it. The results of this command are sent to
standard output when the list of editing commands is finished, regardless of
what happens to the current line in the pattern space.
"