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.