Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: (s,:,) made right ("" is also an element)
On Fri, 13 Mar 2015 11:12:08 +0100, Marc Chantreux wrote:
> hello,
>
> say i have
>
> PATH="/usr/bin::/bin"
> print -l ${(s,:,)PATH}
> foo=( ${(s,:,)PATH} )
> print $#foo
>
> because i have an empty element (which is also an element)
>
> i got
>
> /usr/bin
> /bin
> 2
>
>
> i expect
>
> /usr/bin
>
> /bin
> 3
>
> does someone know how to fix zsh?
print -l "${(@s,:,)PATH}"
foo=("${(@s,:,)PATH)")
It's described in the manual:
For historical reasons, the usual behaviour that empty
array elements are retained inside double quotes is
disabled for arrays generated by splitting; hence the
following:
line="one::three"
print -l "${(s.:.)line}"
produces two lines of output for one and three and elides
the empty field. To override this behaviour, supply the
"(@)" flag as well, i.e. "${(@s.:.)line}".
--
Michał Politowski
Talking has been known to lead to communication if practiced carelessly.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author