Re: encountered a sed POSIX gotcha (GNU vs. BSD)

"Tim Chase [email protected] [sed-users]" <[email protected]> Sun, 6 May 2018 17:35:13 -0500
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
On 2018-05-06 13:32, Daniel Goldman [email protected] [sed-users]
wrote:
> Can anyone else find ';' mentioned in POSIX documentation? I
> looked, did not seem any mention of using ';' to separate commands.

From the same POSIX spec I linked to, right above the previous text I
quoted I found this:

"Editing commands other than {...}, a, b, c, i, r, t, w, :, and # can
be followed by a <semicolon>, optional <blank> characters, and
another editing command."

> To me, having ';' capability seems pretty essential. If POSIX does
> not mention ';' between commands, it would seem POSIX is maybe
> obsolete, in need of updating.

So the ";" separating commands *is* part of POSIX.

> If I was designing from scratch, I think gnu sed probably has it
> "right" here, because sed should be able to see that the
> right-brace is terminating the { } group. How does the ';' help
> figure that out? To me ';}' seems OK (like an odd emoticon!), but
> just '}' seems better.

I agree with the sentiment here -- it's how I found it because I'm
usually in a GNU environment and I usually omit it, but got stung
testing a command on OpenBSD that had worked on Debian.

> I tend to take gnu sed as the "truth". It seems to me the best /
> most functional version. But maybe I am wrong. Which takes
> precedence: gnu sed behavior (my vote) or POSIX specification?

I think this is why I lean towards the GNU convention of a
POSIXLY_CORRECT environment variable.  For those cases where POSIX
compliance matters, you can get it; yet without POSIXLY_CORRECT in
the environment, it shouldn't break existing non-POSIX scripts.  And
if you claim you are POSIXLY_CORRECT via your environment and aren't
compliant, it should balk at such violations and error out.

-tim