Home > Mobile >  What does the percentage sign in zsh shell come from?
What does the percentage sign in zsh shell come from?

Time:10-26

When I run this piece of code (from a tutorial to binary security), I always get an "%" in my zsh shell. Where do these percentage signs come from and how to get rid of them?

#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%

CodePudding user response:

I found this comment on 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=''

CodePudding user response:

You have output text without telling the terminal to move the cursor to the start of the next time.

Rather than displaying a prompt on the same line as other text, zsh moves the cursor to the next line after outputting % to indicate it has done so.

To move the cursor as you should, replace

printf("%s", buf);

with

printf("%s\n", buf);
  •  Tags:  
  • c zsh
  • Related