But it doesn't work the way it should. Sorry, I should have given an
example: With GNU sed 4.1.5,
echo x | sed 's&x&ab\&c&'
results in
abxc
rather than
ab&c
which is what is returned by the seds on AIX, BSDs, Solaris, IRIX,
Tru64, and reading SUSv3, I think it does not specify which is right.
Yes, it is undefined and the current behavior is more coherent with what
is done on the LHS of the `s' command. There, you want to strip slashes
or the following command
s/a\/b//
will rely on the regex matcher matching a literal slash for the escape
\/. This behavior changed in 4.1.x as part of a general reorganization
of the sed parser to better support 7-bit multibyte character sets (e.g.
ISO-2022) in the sed commands. In the command above, sed sees
s&x&ab\&c&
as if it was:
s/x/ab&c/
The same behavior applies to the LHS: backslashed items are *not* passed
down to the regex matcher. For example, in
s|a\|b||
older (up to 4.0.x) GNU seds will parse \| as a special escape
(alternation) but 4.1.x and non-GNU seds will parse it as a literal pipe.
Paolo