Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: printf newline
- X-seq: zsh-users 22103
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- Subject: Re: printf newline
- Date: Mon, 7 Nov 2016 16:51:35 +0000
- Cc: Zsh-Users List <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=sIjUxvjsdNMqWTM 6yz6FkPty644=; b=thRpbYH/A5FQKwgmujRWP1ftbViHHF/f5ImpSpOx3xQ4Wkw n/8eK5FVBw4I7mQaX50Z5P6R0VKpfSeGjdspPS6Nz7xOpzrwVCqLEacBtL0F0Wxc 7BIE2xkdH1I1eAV7AQS4e0RtrOvvXQYzzQeRoyIfgvMmQ1O2rTk4C6DjT4VI=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=smtpout; bh=sIjUxvjsdNMqWT M6yz6FkPty644=; b=IJLgRmSvlXB8lNO6SaRTxbvI8upvncB4kZJDqqKB9gbJjc qB4ieqHhih4/dqKhA1yRCpN1X7FfPE+8XLb7eWsd7xphlgkz/LfFmbmctVznpQey Z/e68heL7AxWGBi1xur4mrb81JI7ucGWv0fJ/nPLrVLO0acvhCw4C5ZmoUADE=
- In-reply-to: <20161107094629.0f762bc7@pwslap01u.europe.root.pri>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CGME20161107082025epcas3p2d5ebaf5a3e7b4f9e3373715666e940d9@epcas3p2.samsung.com> <CAEyXbzeLjC9DVedmzuFJxAmfr+aUBQou+ZFeGsVSBQwcMK0hvQ@mail.gmail.com> <20161107094629.0f762bc7@pwslap01u.europe.root.pri>
Peter Stephenson wrote on Mon, Nov 07, 2016 at 09:46:29 +0000:
> 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.)
>
I think the question was, why the \n and the textb weren't used.
The answer is that printf's interface is different from echo's. printf
interprets its first argument as a format string that describes how to
use the remaining arguments. The format string "texta" instructs to
print "texta" and to ignore any further arguments. The "%" is then
generated by the PROMPT_* options.
For the \n to be interpreted by printf, it must be in the first
argument. Adding the details Peter described gives:
printf 'texta\ntextb\n'
which would do what you want.
Cheers,
Daniel
> 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