UNIX 中的特殊字符
我想在名为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在按
退格
之前按Ctrl+V
。这告诉 shell 按字面意思处理接下来的击键,而不是解释其含义。根据终端的设置方式,
退格
键可能会被解释为删除
,因此您可能需要按Ctrl+H
而不是backspace
在文件中获取backspace
字符。Hit
Ctrl+V
before hittingbackspace
. 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 asdelete
, so you might need to hitCtrl+H
instead ofbackspace
to get abackspace
character in your file.键入 ctrl-v、ctrl-h。
ctrl-v 表示“按字面插入下一个控制字符”。光标应更改为突出显示的插入符号。
ctrl-h 是退格字符。看起来像在 ed 中,输入 ctrl-h 而没有 ctrl-v 也会插入一个文字退格键,但在其他上下文中,crtl-h 可能有其他含义,您需要先按 ctrl-v。
编辑:通过上述步骤,od -cb 给了我:
看起来是正确的。
当我用 ctrl-v、Backspace(而不是 ctrl-h)再次尝试时,它给出的结果是
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:
which looks correct.
When I tried it again with ctrl-v, Backspace (as opposed to ctrl-h), it instead gave
177 is the ascii octal code for DEL, not Backspace. This may vary by system, though.