bug-bash
[Top][All Lists]
Advanced

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

Re: how to keep newlines in ``


From: Marc Herbert
Subject: Re: how to keep newlines in ``
Date: Thu, 27 Aug 2009 09:26:57 +0100
User-agent: Thunderbird 2.0.0.21 (X11/20090320)

Greg Wooledge a écrit :
> On Wed, Aug 26, 2009 at 03:04:16PM -0400, Sam Steingold wrote:
>> foo=`ls`
>> echo $foo
> 
> echo "$foo"

What Greg did not explicitly said:

95% of the time you write $foo unquoted, you are wrong and should have
written double-quoted "$foo" instead.

This not just about newlines. See "A Guide to Unix Shell Quoting" for
details: http://www.mpi-inf.mpg.de/~uwe/lehre/unixffb/quoting-guide.html

Another better practice is to use printf, since $foo could start with a
minus sign:

  printf '%s' "$foo"




reply via email to

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