bug-bash
[Top][All Lists]
Advanced

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

Re: Inconsistent quote and escape handling in substitution part of param


From: Eric Blake
Subject: Re: Inconsistent quote and escape handling in substitution part of parameter expansions.
Date: Tue, 28 Feb 2012 10:16:38 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1

On 02/28/2012 09:54 AM, John Kearney wrote:
> On 02/28/2012 05:22 PM, Roman Rakus wrote:
>> On 02/28/2012 05:10 PM, John Kearney wrote:
>>> wrap it with single quotes and globally replace all single quotes
>>> in the string with '\''
>> single quote and slash have special meaning so they have to be
>> escaped, that's it. \'${var//\'/\\\'}\' it is not quoted, so it
>> undergoes word splitting. To avoid it quote it in double quotes,
>> however it changes how slash and single quote is treated. 
>> "'${var//\'/\'}'"
>>
>> Wasn't it already discussed on the list?
>>
>> RR
>>
> It was discussed but not answered in a way that helped.

POSIX already says that using " inside ${var+value} is non-portable;
you've just proven that using " inside the bash extension of
${var//pat/sub} is likewise not useful.

> 
> Now I'm not looking foe a workaround, I want to understand it.
> Now you say they are treated special what does that mean and how can I
> escape that specialness.

By using temporary variables.  That's the only sane approach.

> 
> Or show me how without using variables
> to do this
> test=test\'string
> 
> [ "${test}" = "${test//"'"/"'"}" ] || exit 999

exit 999 is pointless.  It is the same as exit 231 on some shells, and
according to POSIX, it is allowed to be a syntax error in other shells.

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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