[Top][All Lists]

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

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

From: John Kearney
Subject: Re: Inconsistent quote and escape handling in substitution part of parameter expansions.
Date: Tue, 28 Feb 2012 17:10:40 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:10.0) Gecko/20120129 Thunderbird/10.0

this all started with a wish to single quote a variable. Doesn't matter
why I have multiple solutions to that now.

But it it an interesting problem for exploring how escaping works in
variable expansion.

so for the test case the goal is to take a string like
wrap it with single quotes and globally replace all single quotes in the
string with '\''

its a workaround because it doesn't work all the time you would need
something more like this
IFS= echo \'${test//"'"/\'\\\'\'}\'" "

On 02/28/2012 05:01 PM, Greg Wooledge wrote:
> On Tue, Feb 28, 2012 at 04:52:48PM +0100, John Kearney wrote:
>> The standard work around you see is
>>              echo -n \'${1//\'/\'\\\'\'}\'" "
>>  but its not the same thing
> Workaround for what?  Not the same thing as what?  What is this pile
> of punctuation attempting to do?
>> # why does this work, this list was born of frustration, I tried
>> everything I could think of.
>> echo \'${test//"'"/\'\\\'\'}\'" "
>> 'weferfds'\''dsfsdf'
> Are you trying to produce "safely usable" strings that can be fed to
> eval later?  Use printf %q for that.
> imadev:~$ input="ain't it * a \"pickle\"?"
> imadev:~$ printf '%q\n' "$input"
> ain\'t\ it\ \*\ a\ \"pickle\"\?
> printf -v evalable_input %q "$input"
> Or, y'know, avoid eval.
> Or is this something to do with sed?  Feeding strings to sed when you
> can't choose a safe delimiter?  That would involve an entirely different
> solution.  It would be nice to know what the problem is.

reply via email to

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