在 csh 脚本的 sed 调用中找不到事件

Jig*_*dhi 3 shell tcsh csh quoting

我尝试了删除大括号之间的文本时给出的代码

但是我正面临着关于 sed 事件的这个不同的错误。

文件包含:

This is {
{the multiline
text} file }
that wants
{ to {be
changed}
} anyway.
Run Code Online (Sandbox Code Playgroud)

sed ':again;$!N;$!b again; s/{[^}]*}//g' file

锻炼中可能出了什么问题?

错误

N: Event not found.
Run Code Online (Sandbox Code Playgroud)

cuo*_*glm 5

您必须逃脱!以防止csh/tcsh执行历史扩展。尽管您!用单引号编写,但它们仍然进行历史扩展。

尝试:

sed ':again;$\!N;$\!b again; s/{[^}]*}//g' file
Run Code Online (Sandbox Code Playgroud)

或者您可以编写一个脚本调用-f script.sed(阅读sed 常见问题)。