On Thu, 2022-01-13 at 10:04 +0300, Oğuz via austin-group-l at The Open
Group wrote:
> > a) Is it defined, how the unescaping of delimiters vs. special
> > characters happens?
> > Consider the following example:
> > s(\\((X(
> > There are at least two ways to parse that:
> 
> I see only one. From left to right:
> * `s' is the command verb,
> * `(' is the designated delimiter,
> * `\\' is the RE,
> * `(' is the first closing delimiter,
> * the empty string is the replacement part,
> * `(' is the second closing delimiter,
> * and `X' and `(' are the flags.

And where does it say that? I mean in the standard.
I.e. where does it say, that parsing is only allowed to happen in one
stage from left to right, especially not only with respect to an RE
itself, but also when an RE is embedded in a command with delimiters.

Where does it say, whether:
s.[.].X.
is:
a) s/[/]/
   followed by X.

or:

b) s/[.]/X/

IMO that is either unspecified, or would only follow if there was a
line that says something like:
"A RE, even it's with delimiters (like in a s-command), is parsed all
at once from left to right, as characters occur".


It rather just says (in the description of the sed utility):
"Within the BRE and the replacement, the BRE delimiter itself can be
used as a literal character if it is preceded by a <backslash>."

But since the above 2nd do isn't preceded by a \, but rather just
enclosed by [ ], that would IMO rather imply, that it *is* a delimiter
(at least by that wording).



> > E.g. AFAIU:
> > s.\..X.
> > would be the same as:
> > s/./X/
> > and '.' would be used as special character.
> 
> I disagree. "literal character" means the character itself. `s.\..X.'
> would be the same as `s/\./X/', as per the standard.

Well that's at least not how one widely used implementations of sed
does it:

GNU's sed:
$ printf '%s\n' '.' | sed 's.\..X.'
X
$ printf '%s\n' 'a' | sed 's.\..X.'
X


But even if GNU sed was just wrong here, than my original point would
still apply - just the other way round:

Then, with a delimiter that is also a special character, the special
character would no longer be usable as such.


btw: busybox sed, behaves as you say:
$ printf '%s\n' '.' | busybox sed 's.\..X.'
X
$ printf '%s\n' 'a' | busybox sed 's.\..X.'
a

At least that shows that I'm not the only one confused by the wording
of the standard ;-)



Thanks,
Chris.

  • sed and deli... Christoph Anton Mitterer via austin-group-l at The Open Group
    • Re: sed... Don Cragun via austin-group-l at The Open Group
      • Re:... Christoph Anton Mitterer via austin-group-l at The Open Group
    • Fwd: se... Oğuz via austin-group-l at The Open Group
      • Re:... Christoph Anton Mitterer via austin-group-l at The Open Group
        • ... Christoph Anton Mitterer via austin-group-l at The Open Group
        • ... Oğuz via austin-group-l at The Open Group
          • ... Don Cragun via austin-group-l at The Open Group
            • ... Oğuz via austin-group-l at The Open Group
              • ... Christoph Anton Mitterer via austin-group-l at The Open Group
                • ... Oğuz via austin-group-l at The Open Group
            • ... Christoph Anton Mitterer via austin-group-l at The Open Group
          • ... Christoph Anton Mitterer via austin-group-l at The Open Group

Reply via email to