我有一个文件,其开头如下:
[global]
pid = /var/run/php-fpm/php-fpm.pid
error_log = /var/log/php5-fpm.log
并想更换
error_log = /var/log/php5-fpm.log
和
error_log = /var/log/php-fpm/error.log
我想为此使用一个脚本并执行以下操作:
search='error_log = /var/log/php5-fpm.log'
replace='error_log = /var/log/php-fpm/error.log'
for file in `find -name 'php-fpm.conf'`; do
grep "$search" $file &> /dev/null
if [ $? -ne 0 ]; then
echo "Search string not found in $file!"
else
sed -i "s#$search#$replace#" $file
fi
done
这会引发以下错误:
sed: -e expression #1, char 0: no previous regular expression sed: -e expression #1, char 0: no previous regular expression