On Wed, 22 Oct 2014 10:46:43 -0700 Philip Guenther <guent...@gmail.com>
wrote:

> On Wed, Oct 22, 2014 at 8:37 AM, Christopher Zimmermann
> <chr...@openbsd.org> wrote:
> > $ sed -e "{ y/o/u/ }"
> > sed: 1: "{ y/o/u/ }": extra text at the end of a transform command
> >
> > but this is allowed according to the manual:
> >
> >      Functions can be combined to form a function list, a list of
> > sed functions separated by newlines, as follows:
> >
> >            { function
> >              function
> >              ...
> >              function
> >            }
> >
> >      The `{' can be preceded or followed by whitespace.  The
> > function can be preceded by whitespace as well.  The terminating
> > `}' must be preceded by a newline or optional whitespace.
> 
> That looks like a documentation bug to me.  To quote the POSIX spec:
> ----------
> [2addr] {editing command
> editing command
> ...
> } Execute a list of sed editing commands only when the pattern space
> is selected. The
> 
>                   list of sed editing commands shall be surrounded by
> braces and separated by
>                   <newline> characters, and conform to the following
> rules. The braces can be
>                   preceded or followed by <blank> characters. The
> editing commands can be
>                   preceded by <blank> characters, but shall not be
> followed by <blank> characters.
>                   The <right-brace> shall be preceded by a <newline>
> and can be preceded or
>                   followed by <blank> characters.
> ----------
> 
> So the newline before the close-brace is required.  Since the code
> matches the spec, I think we should change the doc to match both of
> them.  Or is there some reason this extension is required?

I just patched sysutils/findlib:

$OpenBSD: patch-src_findlib_Makefile,v 1.5 2014/10/22 14:56:42 chrisz Exp $
--- src/findlib/Makefile.orig   Wed Oct 15 13:07:40 2014
+++ src/findlib/Makefile        Wed Oct 22 16:54:22 2014
@@ -74,7 +74,7 @@ topfind.ml: topfind.ml.in
        if [ "$(ENABLE_TOPFIND_PPXOPT)" = "true" ]; then                 \
                cp topfind.ml.in topfind.ml;                             \
        else                                                             \
-               sed -e '/PPXOPT_BEGIN/,/PPXOPT_END/{d}' topfind.ml.in    \
+               sed -e '/PPXOPT_BEGIN/,/PPXOPT_END/ d' topfind.ml.in    \
                        > topfind.ml ;                                   \
        fi
 
gnu sed is more permissive here:

{ commands }
    A group of commands may be enclosed between { and } characters.
    This is particularly useful when you want a group of commands
    to be triggered by a single address (or address-range) match. 

But I don't expect to stumble over non portable sed code like that
often.

Christopher


-- 
http://gmerlin.de
OpenPGP: http://gmerlin.de/christopher.pub
F190 D013 8F01 AA53 E080  3F3C F17F B0A1 D44E 4FEE

Attachment: signature.asc
Description: PGP signature

Reply via email to