Can't escape single quotes in shell
Posted
by user13743
on Super User
See other posts from Super User
or by user13743
Published on 2010-04-01T15:22:01Z
Indexed on
2010/04/01
15:23 UTC
Read the original article
Hit count: 313
command-line
|escape-characters
I'm trying to make a command to do a perl substitution on a batch of php files in a directory. The string I want to replace has single quotes in it, and I can't get it to properly escape the in shell.
I tried echoing the string with unescaped quotes, to see what perl would be getting: echo 's/require_once('include.constants.php');/require_once('include.constants.php');require_once("./functions/include.session.inc.php");/g'
and it doesn't have the single-quotes in the result:
s/require_once\(include.constants.php\);/require_once\(include.constants.php\);require_once\("\./functions/include\.session\.inc\.php"\);/g
However, when I try to escape the single quotes:
echo 's/require_once\(\'include\.constants\.php\'\);/require_once\(\'include\.constants\.php\'\);require_once\("\./functions/include\.session\.inc\.php"\);/g'
I get the prompt to complete the command:
>
What I want it to parse to is this:
What am I doing wrong?
s/require_once\('include.constants.php'\);/require_once\('include.constants.php'\);require_once\("\./functions/include\.session\.inc\.php"\);/g
© Super User or respective owner