shell 替换阵列和sed WP配置时出错

nhn9ugyo  于 2023-02-05  发布在  Shell
关注(0)|答案(1)|浏览(135)
newwpuser=$cpuser"_"$wpuser
newwpdb=$cpuser"_"$wpdb
wpdb=($(find . -name "wp-config.php" -print0 | xargs -0 -r grep -e "DB_NAME" | cut -d \' -f 4))
wpuser=($(find . -name "wp-config.php" -print0 | xargs -0 -r grep -e "DB_USER" | cut -d \' -f 4))
wpconfigchanges=($(find . -name wp-config.php -type f))

for i in "${wpconfigchanges[@]}"; do -exec sed -i -e "/DB_USER/s/'$wpuser'/'$newwpuser'/" | -exec sed -i -e "/DB_NAME/s/'$wpdb'/'$newwpuser'/"; done

我试图运行以上为了找到所有的wordpress配置和附加的数据库用户和dbname与cpuser_
但是-我得到了下面的错误;

./test.sh: line 85: -exec: command not found
./test.sh: line 85: -exec: command not found

我是否输入了错误的执行命令?
执行时输入CPUser

dgjrabp2

dgjrabp21#

是的,您输入了错误的exec命令。-exec选项应该单独写在一行中。另外,您需要在每个-exec命令的末尾添加;,以指示命令的结束。
以下是您的脚本的更正版本:

newwpuser=$cpuser"_"$wpuser
newwpdb=$cpuser"_"$wpdb
wpdb=($(find . -name "wp-config.php" -print0 | xargs -0 -r grep -e "DB_NAME" | cut -d \' -f 4))
wpuser=($(find . -name "wp-config.php" -print0 | xargs -0 -r grep -e "DB_USER" | cut -d \' -f 4))
wpconfigchanges=($(find . -name wp-config.php -type f))

for i in "${wpconfigchanges[@]}"; do
  sed -i -e "/DB_USER/s/'$wpuser'/'$newwpuser'/" $i
  sed -i -e "/DB_NAME/s/'$wpdb'/'$newwpuser'/" $i
done

相关问题