UNIX 中的特殊字符

发布于 2024-08-29 04:13:04 字数 176 浏览 2 评论 0原文

我想在名为 junk 的文件中逐字添加退格字符。所以我做了以下事情
$ 编辑
一个
我的名字是 happy\b (这里 b 表示我输入了退格键,因此 \ 消失并且光标位于 y 之后)
.
w垃圾
q

但是当我这样做时
$ od -cb 垃圾
它不显示退格键。

I want to add backspace character literally in my file named junk. So I did following
$ ed
a
my name is happy\b (here b means I typed backspace so \ gets disapperaed and cursor sits sfter y)
.
w junk
q

But when I do
$ od -cb junk
it doesn't show backspace.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过期以后 2024-09-05 04:13:04

在按退格之前按Ctrl+V。这告诉 shell 按字面意思处理接下来的击键,而不是解释其含义。

根据终端的设置方式,退格键可能会被解释为删除,因此您可能需要按Ctrl+H而不是backspace 在文件中获取 backspace 字符。

Hit Ctrl+V before hitting backspace. That tells the shell to treat the following keystroke literally, rather than interpreting its meaning.

Depending on how your terminal is set up, the backspace key might be interpreted as delete, so you might need to hit Ctrl+H instead of backspace to get a backspace character in your file.

情栀口红 2024-09-05 04:13:04

键入 ctrl-v、ctrl-h。

ctrl-v 表示“按字面插入下一个控制字符”。光标应更改为突出显示的插入符号。

ctrl-h 是退格字符。看起来像在 ed 中,输入 ctrl-h 而没有 ctrl-v 也会插入一个文字退格键,但在其他上下文中,crtl-h 可能有其他含义,您需要先按 ctrl-v。

编辑:通过上述步骤,od -cb 给了我:

$ od -cb file
0000000   h   e   l   l   o  \b  \n
        150 145 154 154 157 010 012
0000007

看起来是正确的。

当我用 ctrl-v、Backspace(而不是 ctrl-h)再次尝试时,它给出的结果是

$ od -cb file
0000000   h   e   l   l   o 177  \n
        150 145 154 154 157 177 012
0000007

177 是 DEL 的 ascii 八进制代码,而不是 Backspace。不过,这可能会因系统而异。

Type ctrl-v, ctrl-h.

ctrl-v says 'insert the next control character literally'. The cursor should change to a highlighted caret.

ctrl-h is the backspace character. It looks like in ed, typing ctrl-h without ctrl-v also inserts a literal backspace, but in other contexts, crtl-h may have some other meaning, and you will need to press ctrl-v first.

EDIT: With the above steps, od -cb gave me:

$ od -cb file
0000000   h   e   l   l   o  \b  \n
        150 145 154 154 157 010 012
0000007

which looks correct.

When I tried it again with ctrl-v, Backspace (as opposed to ctrl-h), it instead gave

$ od -cb file
0000000   h   e   l   l   o 177  \n
        150 145 154 154 157 177 012
0000007

177 is the ascii octal code for DEL, not Backspace. This may vary by system, though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文