bug-coreutils
[Top][All Lists]
Advanced

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

Re: weird echo behaviour...


From: Paul Jarc
Subject: Re: weird echo behaviour...
Date: Thu, 16 Sep 2004 11:29:13 -0400
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux)

"Alfred M. Szmidt" <address@hidden> wrote:
> Could someone explain the following behaviour for me?  Because I sure
> do not understand it.
>
> address@hidden:/tmp/foo$ touch 1 2 3 4 5
> address@hidden:/tmp/foo$ foo=`ls`
> address@hidden:/tmp/foo$ /bin/echo $foo
> 1 2 3 4 5
> address@hidden:/tmp/foo$ /bin/echo "$foo"
> 1
> 2
> 3
> 4
> 5

I assume the newlines are the part you don't understand.  Command
substitution works by the shell creating a pipe to capture the output;
when ls sees that it is writing to a pipe, it defaults to -1 instead
of -C.  When the variable expansion is unquoted, $foo is split into
words passed as separate arguments, and echo separates them with
spaces.  When it is quoted, the newlines are retained within the
single argument, and echo writes that argument as-is.


paul




reply via email to

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