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

Re: PATCH: bug in ${(z)...} with newlines



On Wed, Jun 9, 2010 at 6:07 AM, Peter Stephenson <pws@xxxxxxx> wrote:
> This must be a bug, mustn't it?
>
> % foo=$'one\ntwo'
> % print ${(z)foo}
> one ; two

I'm pretty sure that's intentional, so that when the newline is
removed by splitting, the join is still a semantically equivalent
shell expression.  Otherwise you can't do stuff like this:

foo=(${(q)${(z)foo}})
bar=time
for word in $foo
do if [[ $word == '\;' ]]
   then bar+=($word time)
   else bar+=($word)
   fi
done
eval $bar

In fact if newline is not replaced with semicolon by (z), I think it
becomes impossible to find command words by searching through the
resulting array.

> As far as splitting arguments goes, the newline is just whitespace.

Yes, but (z) is really for parsing, not merely splitting.



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