printf 在 zsh 中添加神秘的尾随 % 字符 [英] printf adds mysterious trailing % character in zsh

查看:63
本文介绍了printf 在 zsh 中添加神秘的尾随 % 字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 zsh 中打印重复的 * 字符.这个答案有一个适用于bash的解决方案:

I want to print repeated * characters in zsh. This answer has a solution that works in bash:

printf '*%.0s' {1..50}

然而,当我在 zsh 中运行它时,我得到了这个输出:

However when I run that in zsh, I get this output:

**************************************************%

其中尾随 % 符号具有反转颜色.这对我来说很神秘,我想知道为什么会发生这种情况,我该如何避免?

where the trailing % sign has inverted colors. This is mysterious to me and I want to know why that happens, and how do I avoid it?

推荐答案

那不是性格,而是缺少性格.

That's not a character, it's the lack of a character.

如果输出的最后一行没有终止(即没有以换行符结束,\n),zsh 会显示一个反向视频 % 符号.请参阅 http://zsh.sourceforge.net/Doc/Release/Options.html#提示.

If the last line of output is not terminated (i.e. does not end with a newline character, \n), zsh shows a reverse-video % sign. See http://zsh.sourceforge.net/Doc/Release/Options.html#Prompting.

解决方法是只输出一个终止的换行符:

The fix is to just output a terminating newline:

printf '*%.0s' {1..50}; echo

这篇关于printf 在 zsh 中添加神秘的尾随 % 字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆