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

Re: [PATCH] Forcing array interpretation in parameter substitution



On Apr 13,  6:29pm, Sebastian Gniazdowski wrote:
}
} Just realized that this isn't a "5.0.2" or so thing.
} 
} I wonder if there can be any workaround for older versions

This is sort of ugly, because (z) itself is failing to return an array
when the string to be split has only one word.  The workaround described
in users/22497 does the right thing for (s::) but not for (z).

For (z) you need to force array-ness by splitting some other way and
then also add (z).  E.g.:

var="abc"; echo ${${(Afz)reply::=$var}[1]}

Of course if there are embedded newlines that are quoted, (f) will
break them incorrectly, so you need something more like

echo ${${(Aps:\0:z)reply::=$var}[1]}

Which still breaks if you have embedded NUL bytes in $var, but ...



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