Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Feb 2026 14:49:07 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 292912] usr.bin/sed: allow comments after s///
Message-ID:  <bug-292912-227@https.bugs.freebsd.org/bugzilla/>

index | next in thread | raw e-mail

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=292912

            Bug ID: 292912
           Summary: usr.bin/sed: allow comments after s///
           Product: Base System
           Version: 16.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: devnull@apt322.org

Created attachment 267742
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=267742&action=edit
sed to allow # comments after s///

Hello,

According to POSIX SED conformance, it should be possible to use comments (#)
not only on the first line of a SED script, but anywhere at the end flags, with
all text after the comment character (#) being ignored until a new line is
encountered.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html

But on FreeBSD, we got an error:
# sed -e 's/word/newword/ #comments' test.txt
sed: 1: "s/word/newword/ #comments
": bad flag in substitute command: '#'

On GNU sed, it works. On man page
(https://www.gnu.org/software/sed/manual/sed.html#index-_0023-_0028comments_0029),
we can see:

“3.4… be aware that some implementations of sed (which are not POSIX
conforming) may only support a single one-line comment, and then only when the
very first character of the script is a #.”

Therefore, I suggest accepting # as a comment when used after the last flags,
in accordance with POSIX.

Thanks

-- 
You are receiving this mail because:
You are the assignee for the bug.

home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-292912-227>