bug-bash
[Top][All Lists]
Advanced

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

Re: bad case of parameter substitution with quotes (${p//x/y})


From: Chet Ramey
Subject: Re: bad case of parameter substitution with quotes (${p//x/y})
Date: Wed, 23 Jun 2010 22:08:23 -0400
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.7) Gecko/20100111 Lightning/1.0b1 Thunderbird/3.0.1

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    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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