automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

sed: empty BRE and POSIXLY_CORRECT (Was: Re: Package builds fail with PO


From: Alexandre Duret-Lutz
Subject: sed: empty BRE and POSIXLY_CORRECT (Was: Re: Package builds fail with POSIXLY_CORRECT=1)
Date: Fri, 23 Jan 2004 22:02:58 +0100
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

[Cc:ing automake-patches so the discussion gets archived
somewhere.  Why doesn't GNU sed have a mailing list?]

Hi Paolo,

Miloslav Trmac just reported a bug against automake which I
believe is a bug in sed.  It boils down to this:

% echo abc | sed '/b/ s///'
ac
% echo abc | POSIXLY_CORRECT=1 sed '/b/ s///'
abc

I've found the following explanation in the manual

|    Unless `POSIXLY_CORRECT' is set, the empty regular expression `//'
|    repeats the last regular expression match (the same holds if the
|    empty regular expression is passed to the `s' command).  Note that
|    modifiers to regular expressions are evaluated when the regular
|    expression is compiled, thus it is illegal to specify them
|    together with the empty regular expression.  If `POSIXLY_CORRECT'
|    is set, instead, `//' is the null match: this behavior is mandated
|    by POSIX, but it would break too many legacy `sed' scripts to
|    blithely change GNU `sed''s default behavior.

as well as this comment in regex.c:compile_regex()

| /* My reading of IEEE Std 1003.2-1992 is that // means the empty RE.
|    But historical and common practice is that // "matches the last RE";
|    thus this use of POSIXLY_CORRECT. */

that latter one is interesting since it gives a date.

In a more recent version of that standard, IEEE Std 1003.1-2003
(http://www.opengroup.org/onlinepubs/007904975/utilities/sed.html),
I can read just the converse:

| Regular Expressions in sed
|
| The sed utility shall support the BREs described in the Base
| Definitions volume of IEEE Std 1003.1-2001, Section 9.3, Basic
| Regular Expressions, with the following additions:
[...]
| * If an RE is empty (that is, no pattern is specified) sed
|   shall behave as if the last RE used in the last command
|   applied (either as an address or as part of a substitute
|   command) was specified.

I believe this detail was probably omitted in previous versions.
However, now that it is explicitly mentioned, the current
behavior of sed when POSIXLY_CORRECT is set seems incorrect.

-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]