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

Re: Bug with bash emulation regarding ':'



On 2/14/12 12:41 PM, Peter Stephenson wrote:
> On Sun, 5 Feb 2012 20:11:33 +0000
> Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
>> There's still a difference from bash...
> 
> namely that in bash
> 
>   test_split_var=
>   : ${test_split_var:=$(echo "one
>   two
>   three")}
>   echo "$test_split_var"
> 
> outputs the original string, with no splitting on the returned variable
> from the command substitution.  zsh does split the command substitution
> before the assignment when in sh emulation (the same split array that
> later gets substituted onto the command line), so the newlines turn into
> spaces when the string is joined up again.

Bash doesn't split word in ${parameter:OPword} because Posix says not
to:

"word shall be subjected to tilde expansion, parameter expansion, command
substitution, and arithmetic expansion."

A later interpretation adds quote removal to the list.

> 
> However,
> 
>   test_split_var=
>   echo ${test_split_var:=$(echo "one
>   two
>   three")}
> 
> does perform splitting, evidently after the assignment has been done
> because the value assigned to test_split_var is (of course) as before.

The same thing actually happens in both examples; you just look at the
results of the expansion in the second case.  The rhs gets expanded,
but not split, assigned to test_split_var, and that becomes the result
of the parameter expansion.  Those results get split, since the param
expansion doesn't occur within double quotes, and passed to `:' and echo
as arguments.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@xxxxxxxx    http://cnswww.cns.cwru.edu/~chet/



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