[Bug 292912] usr.bin/sed: allow comments after s///
- In reply to: bugzilla-noreply_a_freebsd.org: "[Bug 292912] usr.bin/sed: allow comments after s///"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 04 Feb 2026 10:21:42 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=292912
Dag-Erling Smørgrav <des@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |des@FreeBSD.org
Resolution|--- |Works As Intended
Status|New |Closed
--- Comment #1 from Dag-Erling Smørgrav <des@FreeBSD.org> ---
There is no foundation in either POSIX or the GNU sed manual for your claim
that comments should be allowed after a command. Both POSIX and the GNU sed
manual describe '#' solely as a command which causes the rest of the line to be
ignored. Like any other command, it must be separated from a preceding command
by either a semicolon or a blank line. So these variants are allowed by POSIX
and supported by BSD sed:
% echo foo | sed -e 's/foo/bar/; # comment'
bar
% echo foo | sed -e $'s/foo/bar/\n# comment'
bar
% echo foo | sed -e 's/foo/bar/' -e '# comment'
bar
but this variant is neither allowed by POSIX nor supported by BSD sed:
% echo foo | sed -e 's/foo/bar/ # comment'
sed: 1: "s/foo/bar/ # comment
": bad flag in substitute command: '#'
This last variant appears to be supported by GNU sed, but, importantly, not
mentioned in the documentation.
The passage you quote from the GNU sed manual does not refer to comments that
follow a command, but to the fact that some implementations (not including BSD
sed) only allow a comment on the first line of the script.
--
You are receiving this mail because:
You are the assignee for the bug.