[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] printf -v

From: Pierre Gaston
Subject: Re: [Help-bash] printf -v
Date: Sun, 8 May 2016 19:22:21 +0300

On Sun, May 8, 2016 at 6:42 PM, Wu Shuangrong <address@hidden> wrote:

> Hello,
> I am trying to save a string with a trailing newline to a variable,
> following is what i did:
> printf -v var1 “%s\n” xyz
> now when i echo $var1 it seems the newline disappears, as echo adds a
> newline to the end of the output, so i expected a blank line appeared on
> the screen, but that’s not what happened. So what’s happening here?
> Thanks,
> Shuangrong
> if you don't quote $var1 bash splits the variable on space tab and
newlines (by default, this can be changed) and then remove these.

you should use: echo "$var1", or even better: printf '%s\n' "$var1"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]