On 6/23/10 4:54 AM, Yves wrote: > Description: > I want to generate a "bash-proof" string by enclosing it in > single quotes and managing enclosed single quotes. Basically, I > would replace << word1 word'2 >> with << 'word1 word'"'"'2' >>. > I can't find the syntax for doing this with the ${p//x/y} > substitution (see example below). > Actually, command #4 /does/ produce the right substitution, but > as soon as I enclose it in double quotes, extra double-quotes > appear, and I can't see the logic behind it, nor the logic > behind my further tests' results.
When bash encounters a double quote inside a double-quoted parameter expansion, it opens a new quoting context. That's why the single quote doesn't act as a special character. However, bash doesn't remove the inner double quotes, because they're not one of the characters that's special within double quotes. The latter is arguably a bug, but it's the way bash has behaved for a long time. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/