简体   繁体   中英

Search and Replace Linux

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??

你需要转义$/字符:

sed "s/require_once('/require_once(\$_SERVER['DOCUMENT_ROOT']\/'/g"

你需要反斜杠 - 在双引号内转义美元符号,否则shell会插入(不存在的)环境变量_SERVER ,用空字符串替换它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM