什么是 Bash 转义字符“\c”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7154800/
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 20:57:07  来源:igfitidea点击:

What is the Bash Escape Character "\c"?

bashunixescapingecho

提问by Keith Pinson

What is the name and function of the \cescape character in Bash? What is its numeric value? I have seen that \cxis a control character, but what about plain \c? It seems that:

\cBash中转义符的名称和作用是什么?它的数值是多少?我已经看到这\cx是一个控制字符,但是普通的\c呢?看起来:

echo -e "Hello World\c"

and

echo -en "Hello World"

are equivalent. However, Python doesn't use it as an escape character, and it is missing from all of the lists of escape characters I found. Is this a Bash-specific behavior?

是等价的。但是,Python 不将它用作转义字符,而且我发现的所有转义字符列表中都缺少它。这是 Bash 特有的行为吗?

回答by paxdiablo

That's actually specific to some versions of echo(I'm pretty sure that \ccame from SysV while the -nversion was a BSD-ism).

这实际上是特定于某些版本的echo(我很确定它\c来自 SysV,而该-n版本是 BSD 主义)。

It simply means don't output the trailing newline.

它只是意味着不要输出尾随换行符。

回答by Andrew Clark

See the echo man pageor the section on echo in the Bash Builtins section of the Bash manual:

请参阅echo 手册页Bash 手册Bash 内置程序部分中有关 echo 的部分

echo interprets the following escape sequences:

...
\c
     suppress further output

echo 解释以下转义序列:

...
\c
     抑制进一步的输出

回答by Russ Clarke

It's the 'End of Text' control character; it informs the Shell that the end of text has been reached.

它是“文本结束”控制字符;它通知 Shell 已到达文本结尾。

Not entirely sure that it's relevant any more, but I could be wrong.

不完全确定它不再相关,但我可能是错的。

here's the doc:

这是文档:

http://en.wikipedia.org/wiki/ASCII#ASCII_control_characters

http://en.wikipedia.org/wiki/ASCII#ASCII_control_characters

and:

和:

http://en.wikipedia.org/wiki/End-of-text_character

http://en.wikipedia.org/wiki/End-of-text_character

回答by Rian Sanderson

Can you update your question with a little more context on how the \c is being used?

你能用更多关于 \c 是如何使用的上下文来更新你的问题吗?

You can use \cto escape control characters that you may, say write to a file, or pipe as input to another command.

您可以使用\c转义控制字符,例如写入文件或管道作为另一个命令的输入。

This will write to the terminal the text "some command" followed by binary ctrl-d (ascii 0x4):

这将向终端写入文本“some command”,后跟二进制 ctrl-d (ascii 0x4):

echo some control string $'\cd' 

See full list of escape characters from the bash man page: http://linux.die.net/man/1/bash

从 bash 手册页查看转义字符的完整列表:http: //linux.die.net/man/1/bash