4

I am trying to do the following search and replace, but for some reason it's not working. I am trying to replace:

require_once('

with

require_once($_SERVER['DOCUMENT_ROOT']/'

Those are the exact srings (slash and single quote included).

This is what I attempted, however I can't get it to work:

find ./ -type f -readable -writable -exec sed -i "s/require_once(\'/require_once($_SERVER['DOCUMENT_ROOT'] . \'\//g" {} \; 

What am I doing wrong??

1
  • Do you get an error message? I think the problem is with the escaping of special characters. Commented Jan 10, 2013 at 18:31

2 Answers 2

5

You need to escape the $ and / characters:

sed "s/require_once('/require_once(\$_SERVER['DOCUMENT_ROOT']\/'/g" 
Sign up to request clarification or add additional context in comments.

1 Comment

One can use @ as delimiter for sed, so you do not need to escape /. e.g.: sed -e 's@/asd/@b@'. But you will still need to escape $.
0

You need to backslash-escape the dollar sign within double quotes, otherwise the shell interpolates the (nonexistent) environment variable _SERVER, replacing it with an empty string.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.