Shell script for replacing string in all PHP-files, for each user
- by Mads Skjern
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?