| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
That's worth discussing. I interpret the POSIX text the same as you do,
that POSIX would require a newline or semicolon before the right-brace.
So on one hand, you seem perfectly right.
OTOH, my understanding was that ';' is used to *separate* sed commands,
not terminate them. The gnu sed manual says, "A semicolon (';') may be
used to separate most simple commands".
Can anyone else find ';' mentioned in POSIX documentation? I looked, did
not seem any mention of using ';' to separate commands.
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.
I know the original sed did not use ';' syntax. I believe there are
still some sed versions that do not support using ';' between commands.
Those versions seem not adequate to me.
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 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?
Perhaps no easy answers here. I have the luxury of just using gnu sed,
so not a problem for me. But yes, script portability matters.
Daniel
On 5/6/2018 5:31 AM, Tim Chase [email protected] [sed-users] wrote:
> Encountered this one yesterday and thought I'd bring it to light.
>
> On a GNU system this works:
>
> sed -n '/pattern/{s/foo/bar/p}'
>
> but fails on BSD sed (tested on OpenBSD & FreeBSD)
>
> sed: 1: "/pattern/{s/foo/bar/p}": bad flag in substitute command: '}'
>
> This is actually POSIX which requires a newline or semicolon before a
> close-brace:
>
> "The <right-brace> shall be preceded by a <newline> or <semicolon>
> (before any optional <blank> characters preceding the <right-brace>)."
>
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_13_03
>
> Thus on a BSD system it needs to have the extra semi-colon:
>
> sed -n '/pattern/{s/foo/bar/p;}'
>
> Unfortunately, I suspect that a lot of scripts out there depend on
> the GNU-specific relaxed (but POSIX-violating) rules, so enforcing
> the POSIX will likely break them. However, I also know that a number
> of GNU tools respect a POSIXLY_CORRECT environment variable which
> might be useful in this situation.
>
> And now you know too.
>
> -tim
>
>
>
>
>
> ------------------------------------
> Posted by: Tim Chase <[email protected]>
> ------------------------------------
>
------------------------------------
------------------------------------
--
------------------------------------
Yahoo Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sed-users/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/sed-users/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/