zsh shell 中的百分号是怎么来的?

What does the percentage sign in zsh shell come from?

当我 运行 这段代码(从教程到二进制安全)时,我总是在我的 zsh shell 中得到一个“%”。这些百分号从何而来,如何去除?

#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
  char buf[256];
  memcpy(buf, argv[1],strlen(argv[1]));

  printf("%s", buf);
}


% ./a.out 234
234%
% ./a.out 23466
23466%
% ./a.out 2
2%

我在 reddit 上找到了这条评论。

Zsh has a nice feature where it can tell you whether the previous command did or didn't have a trailing newline. You can customize what gets printed in this case. I have this option in my ~/.zshrc:

PROMPT_EOL_MARK='%K{red} ' This will print a red block instead of inverted % (or inverted # when you are root). I find it nicer.

You can also set this parameter to empty.

PROMPT_EOL_MARK=''

你没有告诉终端将光标移动到下一次的开始就输出了文本。

zsh 不是在与其他文本相同的行上显示提示,而是在输出 % 后将光标移动到下一行以表明它已经这样做了。

如需移动光标,替换

printf("%s", buf);

printf("%s\n", buf);