Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a shell file which needs to perform a replace of some text in a php file.

The line that needs replacing is:

$database = $db."_db";

The actual sed command needs to contain a variable so not sure what i should be escaping and where?


sed -i s/$db."db"/$DATABASE/ mysql_connect.php


share|improve this question

1 Answer 1

up vote 3 down vote accepted

Enclose the string in single quotes to prevent variable expansion.

sed -i s/'$db."_db"'/$DATABASE/ mysql_connect.php

to replace all occurrences of $db."_db" with the value of $DATABASE.

share|improve this answer
perfect thanks :) – seengee Jul 24 '12 at 11:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.