回显退格键

发布于 2024-11-02 12:33:08 字数 200 浏览 0 评论 0原文

是否可以在 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 技术交流群。

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

发布评论

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

评论(3

甜心 2024-11-09 12:33:08

\b 使光标向左移动,但不会删除该字符。如果要删除则输出一个空格。

对于某些发行版,您可能还需要使用 echo-e 开关:

 -e 启用反斜杠转义的解释

所以它看起来像

 echo -e 'stack\b '

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 of echo:

  -e     enable interpretation of backslash escapes

So it will look like

 echo -e 'stack\b '

Also, files=(*) ; echo "${#files[@]} items".

随梦而飞# 2024-11-09 12:33:08

因此,为了回答有关退格键的实际问题,这将模拟退格键:

echo -e "\b \b"

它将字符向后移动一个,然后回显一个空格,覆盖那里的任何字符,然后再次向后移动 - 实际上删除前一个字符。但它不会返回一行,因此之前的输出不应创建新行:

echo -n "blahh"; echo -e "\b \b"

So to answer the actual question about backspaces this will simulate a backspace:

echo -e "\b \b"

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:

echo -n "blahh"; echo -e "\b \b"
So尛奶瓶 2024-11-09 12:33:08

这并不完全是您所要求的,而且,在伊格纳西奥的回答中,您可以用于这种情况:

echo "$(ls | wc -l) items"

据我所知,您无法打印删除之前字符的字符,甚至无法打印其十六进制数字对应的字符退格键。不过,您可以后退并打印一个空格来删除。使用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:

echo "$(ls | wc -l) items"

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.

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