sed 与 &在变量中 [英] sed with & in variable
本文介绍了sed 与 &在变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用 sed 搜索和替换,并用包含一些特殊符号(如 &
)的变量中的内容替换.
I would like to search and replace with sed and replace with something in a variable which is containing some specials symbols like &
.
例如我做了这样的事情:
For example I done something like that:
sed "s|http://.*|http://$URL|"
其中 URL=1.1.1.1/login.php?user=admin&pass=password
.我认为这是一个问题,因为我在变量中使用了 ?
和 &
.
where URL=1.1.1.1/login.php?user=admin&pass=password
. I thinks it became a problem because I use ?
and &
in my variable.
如何进行搜索和替换?
推荐答案
URL="1.1.1.1/login.php?user=admin&pass=password"
URL=$(echo "$URL" | sed 's/&/\\&/') # substitute to escape the ampersand
echo "$OTHER" | sed "s|http://.*|http://$URL|"
这篇关于sed 与 &在变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文