回显退格键
是否可以在 bash 中回显退格键?
类似的东西
echo $'stack\b'
不应该输出 stac
?或者我错过了什么?
更具体地说,我想将其用于:
ls | wc -l; echo $'\b items'
Is it possible to echo a backspace in bash?
Something like
echo
Shouldn't output stac
? Or I'm missing something?
More specifically, I'd like to use that in:
ls | wc -l; echo
stack\b'
Shouldn't output stac
? Or I'm missing something?
More specifically, I'd like to use that in:
\b items'
stack\b'Shouldn't output stac
? Or I'm missing something?
More specifically, I'd like to use that in:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
\b
使光标向左移动,但不会删除该字符。如果要删除则输出一个空格。对于某些发行版,您可能还需要使用
echo
的-e
开关:所以它看起来像
Also,
files=(*) ;回显“${#files[@]} 项”
。\b
makes the cursor move left, but it does not erase the character. Output a space if you want to erase it.For some distributions you may also need to use
-e
switch ofecho
:So it will look like
Also,
files=(*) ; echo "${#files[@]} items"
.因此,为了回答有关退格键的实际问题,这将模拟退格键:
它将字符向后移动一个,然后回显一个空格,覆盖那里的任何字符,然后再次向后移动 - 实际上删除前一个字符。但它不会返回一行,因此之前的输出不应创建新行:
So to answer the actual question about backspaces this will simulate a backspace:
It will move the character back one, then echo a space overwriting whatever character was there, then moving back again - in effect deleting the previous character. It won't go back up a line though so the output before that should not create a new line:
这并不完全是您所要求的,而且,在伊格纳西奥的回答中,您可以用于这种情况:
据我所知,您无法打印删除之前字符的字符,甚至无法打印其十六进制数字对应的字符退格键。不过,您可以后退并打印一个空格来删除。使用cput,您可以执行许多操作并在屏幕上的任意位置进行打印。
It is not exactly what you're asking for, but also, in the line of Ignacio's answer, you could use for this case:
AFAIK you cannot print a character that deletes the one before, not even printing the char whose hexadecimanl number correspoonds to backspace. You can move back and print a blank space to delete, though. With cput you can do many things and print wherever you want in the screen.