gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:20:12 26 4
gpt4 key购买 nike

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

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”命令

最佳答案

问题的发生可能是因为您的 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

关于linux - 如何在 sed 命令中使用变量来替换属性文件中的属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23169174/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com