Search code examples
czsh

What does the percentage sign in zsh shell come from?


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%

Solution

  • 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);