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.
Look consider this test=teststring echo "${test//str/"dddd"}" test"dddd"ing echo ${test//str/"dddd"} testdddding echo ${test//str/"'"} test'ing echo "${test//str/"'"}" test"'"ing echo "${test//str/'}" # hangs now consider this case test=test\'string echo "${test//"'"/"'"}" test"'"string the match string and the replace string are exhibiting 2 different behaviors. 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. Or show me how without using variables to do this test=test\'string [ "${test}" = "${test//"'"/"'"}" ] || exit 999 Note this isn't the answer [ "${test}" = "${test//'/'}" ] || exit 999