Shell script for replacing string in all PHP-files, for each user

Posted by Mads Skjern on Super User See other posts from Super User or by Mads Skjern
Published on 2013-11-06T09:16:59Z Indexed on 2013/11/06 9:57 UTC
Read the original article Hit count: 237

Filed under:

Each user has some php-files using a shared database commondb. I want to iterate over all users (in users.csv), and in their home folder (e.g. /home/joe) find all php files recursively, and replace each occurrence of "commondb" with their own databasename, e.g. "joedb" for "joe".

I have tried the following:

#!/bin/bash
# Execute like this:
# bash localize.bash users.csv

OLDIFS=$IFS
IFS=","
while read name dummy
  do
    echo $name
    find /home/${name} -name '*.php' -exec sed -i '' 's/commondb/${name}db/g' "{}" \;

  done < $1
IFS=$OLDIFS

for users.csv

joe, Joe J
george, George G

It does not fail, but the files are unchanged. I am quite weak in bash, and I can't figure out how to debug it :/

Can my script be fixed to work?

© Super User or respective owner

Related posts about bash