如何在sed命令中使用变量替换属性文件中的属性值

用户3551469

我可以使用以下命令通过硬编码来更改目标值。

sed -ie s/^target=.*/target=google.com/ url.properties

但是,如果我使用变量,我会报错。我不知道sed命令如何全部工作。我只需要设置构建系统即可。

url = google.com
sed -ie s/^target=.*/target=$url/ url.properties

sed错误:-e表达式#1,字符25:未终止的s命令

阿什什·高尔(Ashish gaur)

因为您URL可能包含/将bash解释为sed语法的问题,所以可能会发生此问题,因此类似的https/www.google.com最终结果是:

sed -ie 's/^target=.*/target=https/www.google.com/' url.properties

我建议分隔任何特殊字符,以免sed引起混淆:

url=google.com
url=`echo $url | sed -e "s/\//\\\\\\\\\//g"` # delimits backslash in URL's
sed -ie "s/^target=.*/target=$url/" url.properties

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章