Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试在 sed 命令找到的行的末尾添加一些文本(路径):
var="/folder1/folder2/folder3" sed -i "/Begins with this text/s/$/$var/" filename
我知道在 sed 命令中使用变量需要双引号,但是如果我使用上述命令,它会给我一条错误消息:
expresssion #1, character 23: unknown option to `s
我究竟做错了什么?
将替换命令中的分隔符更改为不会出现在的内容$var,例如
$var
sed -i "/Begins with this text/s|$|$var|" filename
或转义中的斜线$var:
var="\/folder1\/folder2\/folder3"