引用和 sed 的问题
我正在尝试使用 sed 查找并替换一些文本。具体来说,我试图在可能包含空格的变量周围添加引号。
sed -i 's/$VAR some.file/"$VAR" some.file/g' path/to/file
不幸的是,结果并非预期。我也尝试过反斜杠引号,但没有成功。我在这里缺少什么?
sed命令在Windows/cygwin下执行。
I'm trying to find and replacing some text using sed. Specifically, I'm trying to add quotes around a variable which could contain whitespaces.
sed -i 's/$VAR some.file/"$VAR" some.file/g' path/to/file
Unfortunately, the result is not expected. I've also tried to backslash the quotes, with no luck. What am I missing here?
The sed command is executed under Windows/cygwin.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您忽略了单引号阻止变量替换的事实:
甚至
You're missing the fact that single quotes prevent variable substitution:
or even