2

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.

unacorn
  • 121
  • 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 01:34

1 Answers1

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%