6

我正在为一个键盘上没有返回键的特殊设备制作 SSH 客户端,我的问题是返回键是如何在发送到 shell 的字符串中编码的?它只是'\ n'吗?

4

1 回答 1

6

Then Enter key sends the character 13 = \015 = 0x0d = \r = ^M = CR (carriage return). You can observe that by typing Ctrl+V then Enter in a terminal: Ctrl+V tells the shell to insert the next character literally instead of interpreting it as a command.

You can select a different end-of-line character in stty settings, but not all applications will notice. It's better to use the standard character.

For historical reasons, the character sent by the Enter key on keyboards is not the same character that indicates the end of a line in a text file: the end-of-line character is 10 = \012 = 0x0a = \n = ^J = LF (line feed).

于 2013-07-02T12:12:35.417 回答