bash – 从wp-config.php中读取变量

前端之家收集整理的这篇文章主要介绍了bash – 从wp-config.php中读取变量前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正忙着为一些WP站点编写基本的迁移脚本,我正在尝试通过读取wp-config文件自动创建 mysql数据库用户凭据

我如何从wp-config文件中读取以下变量,以便在bash脚本中有效地结束3个变量:

@H_301_3@/** The name of the database for wordpress */ define('DB_NAME','somedbname'); /** MysqL database username */ define('DB_USER','someusername'); /** MysqL database password */ define('DB_PASSWORD','somerandompassword');

例如我的输出应该有效地给我:

@H_301_3@WPDBNAME=somedbname WPDBUSER=somedbuser WPDBPASS=somerandompassword
试试这个: @H_301_3@WPDBNAME=`cat wp-config.php | grep DB_NAME | cut -d \' -f 4` WPDBUSER=`cat wp-config.php | grep DB_USER | cut -d \' -f 4` WPDBPASS=`cat wp-config.php | grep DB_PASSWORD | cut -d \' -f 4`

猜你在找的Bash相关文章