1

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?

#!/bin/sh

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

Thanks.

robjmills
  • 990
  • 9
  • 26

1 Answers1

3

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.

Zanchey
  • 3,051
  • 22
  • 28