作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我可以使用以下命令通过硬编码更改目标值。
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/
我是一名优秀的程序员,十分优秀!