巴什桑达查找和放大器;替换为特殊字符 [英] Bash Sed Find & Replace With Special Characters

查看:117
本文介绍了巴什桑达查找和放大器;替换为特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到 {AUTH-KEYS,盐} 文件中的 WP-config.php文件和与bash的变量 keysalts 中的内容替换它。

I am trying to find {AUTH-KEYS-SALTS} in the file wp-config.php and replace it with the contents of the bash variable keysalts.

keysalts=`curl -sS https://api.wordpress.org/secret-key/1.1/salt/`
sed -i "s/{AUTH-KEYS-SALTS}/$keysalts/g" wp-config.php

以下几乎工程,但 keysalts 有一堆的特殊字符,如$`。'和sed是越来越糊涂基本上,我怎么什么都逃不过而只是$ keysalts取代{AUTH-KEYS,盐}?

The following almost works, except that keysalts has a bunch of special characters such as $`;'" and sed is getting confused. Basically, how do I escape everything and just replace {AUTH-KEYS-SALTS} with $keysalts?

感谢。

推荐答案

可以使用 perl的其他方式:

perl -i -pe '
  BEGIN { 
    $keysalts = qx(curl -sS https://api.wordpress.org/secret-key/1.1/salt) 
  } 
  s/{AUTH-KEYS-SALTS}/$keysalts/g
' wp-config.php

这篇关于巴什桑达查找和放大器;替换为特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆