[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sed escaping question
From: |
Stepan Kasal |
Subject: |
Re: sed escaping question |
Date: |
Tue, 23 May 2006 20:42:34 +0200 |
User-agent: |
Mutt/1.4.2.1i |
Hello,
On Tue, May 23, 2006 at 07:08:43PM +0200, Ralf Wildenhues wrote:
> Regarding this: (info Autoconf "Limitations of Usual Tools"):
>
> | Portable `sed' regular expressions should use `\' only to escape
> | characters in the string `$()*.0123456789[\^n{}'. For example,
> | alternation, `\|', is common but Posix does not require its
> | support, so it should be avoided in portable scripts. Solaris
> | `sed' does not support alternation; e.g., `sed '/a\|b/d'' deletes
> | only lines that contain the literal string `a|b'. Similarly, `\+'
> | and `\?' should be avoided.
>
> Does this mean that `]' in a sed regex should not be escaped if it is to
> match a literal `]'?
Definitly. `]' is not a special character in BREs (nor in EREs).
You can choose between `]' and `[]]', but `\]' is undefined.
> Conversely to the second half of the paragraph, can we be certain that
> sed 's|a\|b||'
>
> does what I think it should do, namely remove a literal `a|b' from the
> code, and not invoke alternation? Or should a different delimiter be
> preferred for safety?
I read the Posix definition right now, and I can confirm that it
seems to define this meaning. (I don't know anything about actual
implementations.)
My understanding is that the above paragraph is not speaking about
this; it's a special exception that \<delimiter> denotes the literal
character <delimiter> in the `s' command. (I'm not sure, but perhaps
a clarification could be added there, in paretheses).
Have a nice day,
Stepan