获取“sed 错误 - 非法字节序列”(在 bash 中)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11287564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 22:21:45  来源:igfitidea点击:

Getting "sed error - illegal byte sequence" (in bash)

bashsed

提问by alt

Doing some stream editing to change the nasty Parallels icon. It's poorly developed and embedded into the app itself rather than being an image file. So I've located this sed command that has some good feedback:

进行一些流编辑以更改讨厌的 Parallels 图标。它的开发很差并且嵌入到应用程序本身中,而不是一个图像文件。所以我找到了这个 sed 命令,它有一些很好的反馈:

sudo sed -i.bak s/Parallels_Desktop_Overlay_128/Parallels_Desktop_Overlay_000/g /Applications/Parallels\ Desktop.app/Contents/MacOS/prl_client_app

It returns sed: RE error: illegal byte sequence

它返回 sed: RE error: illegal byte sequence

Can anyone explain what this means? What part of the command is the problem?

谁能解释一下这是什么意思?命令的哪一部分有问题?

回答by ldrg

Try setting the LANGenvironment variable (LANG=C sed ...) or use one of the binary sed tools mentioned here: binary sed replacement

尝试设置LANG环境变量 ( LANG=C sed ...) 或使用这里提到的二进制 sed 工具之一:二进制 sed 替换

Why the error?

为什么会出错?

Without LANG=Csed assumes that files are encoded in whatever encoding is specified in LANGand the file (being binary) may contain bytes which are not valid characters in LANG's encoding (thus you could get 'illegal byte sequence').

没有LANG=Csed 假设文件以指定的任何编码进行编码,LANG并且文件(二进制)可能包含在LANG' 编码中无效的字节(因此您可能会得到'非法字节序列')。

Why does LANG=Cwork?

为什么LANG=C有效?

C just happens to treat all ASCII characters as themselves and non-ASCII characters as literals.

C 恰好将所有 ASCII 字符视为它们自己,将非 ASCII 字符视为文字。

回答by Malstr?m

LANG=Calone didn't do the trick for me but adding LC_CTYPE=Cas well solved it.

LANG=C独自一人并没有为我LC_CTYPE=C解决问题,但添加也解决了它。

回答by rjpeter2

In addition to LANG=Cand LC_CTYPE=C, I had to do LC_ALL=Cto get this to work.

除了LANG=Cand 之外LC_CTYPE=C,我还必须这样做LC_ALL=C才能使其正常工作。

LC_ALLoverrides all individual LC_*categories. Thus, the most robust approach is to use LC_ALL=C sed ...- no need to also deal with the other variables.

LC_ALL覆盖所有单独的LC_*类别。因此,最稳健的方法是使用LC_ALL=C sed ...——无需同时处理其他变量。

回答by Adam Waite

I managed to do it by running:

我设法通过运行来做到这一点:

unset LANG

before the sedcommand.

sed命令之前。

Not sure what I've done or why it works but it did.

不知道我做了什么或为什么它有效,但确实如此。