1

This question already has an answer here:

May I know what does it mean when a '%' appears at the end of the output when I execute my code?

For example:

Hello,World%

Added:

I'm using Mac Os X iTerm2 zsh shell.

My code

echo 'Hello,World' | tr "\n" "\000"

I added the tr command to get rid of the newline at the end.

I'm using vim so I want to get the output without the newline just like if I'm using emacs.

Thank you.

marked as duplicate by don_crissti, Greg Hewgill, Gilles, Stéphane Chazelas, Kusalananda Aug 11 '16 at 6:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Is % your shell prompt? Did you print a newline at the end of your output? – Greg Hewgill Aug 10 '16 at 21:45
  • You could also have used echo 'Hello,World' | tr -d "\n" or, better, echo -n "Hello,World" or printf "Hello,World". And yes, the % is your shell prompt. I don't see how using vim is relevant. – Keith Thompson Aug 10 '16 at 22:01
  • I should have mentioned, `tr "\n" "\000" doesn't just remove the newline, it replaces it with a null character. This will usually have no effect if you're writing to the terminal, but it can matter, particularly if you're writing to a file or to a pipe. – Keith Thompson Aug 11 '16 at 1:34
1

The % is your standard prompt.

Normally this will appear on a line on its own

However this depends on the program you just run to end with a LF character. Most commands do this automatically

eg

% echo hello
hello
% 

However commands don't have to do this. In this case your prompt gets added to the end of the line:

% printf "hello"  
hello% 

In your case you removed the \n from your output with the tr command, and so the prompt appears on the same line.

We can demonstrate this by running your command twice, on the same line:

% echo 'Hello,World' | tr "\n" "\000" ; echo 'Hello,World' | tr "\n" "\000"
Hello,WorldHello,World% 
  • No, in the case of zsh, it's not. See the dup question. – Stéphane Chazelas Aug 11 '16 at 7:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.