Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: printf newline



On Sun, 6 Nov 2016 18:29:44 +0100
Johan DS <victor3xray@xxxxxxxxx> wrote:
> hi
> does anybody has a clou why if I:
> $ printf texta \n textb
> 
> The output is:
> 
> texta%
> 
> and not:
> texta
> textb

(I presume you've missed out some quotes?  In what you show the
backslash would be swallowed up when reading the command line and so
you'd get an "n" rather than a newline.)

There's no implicit newline at the end of printf output, unlike print.
Because the shell needs to know where it is on the terminal (as zsh
handles multiple lines on the screen, unlike most other command line
environments), it goes back to the beginning of the line, swallowing up
the textb.

If you really need, you can "unsetopt prompt_cr", but you're liable to
see side effects.  For most of us it's usually more convenient just to
add the extra newlines.

pws



Messages sorted by: Reverse Date, Date, Thread, Author