zsh-users
 help / color / mirror / code / Atom feed
* (s,:,) made right ("" is also an element)
@ 2015-03-13 10:12 Marc Chantreux
  2015-03-13 10:42 ` Michal Politowski
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Chantreux @ 2015-03-13 10:12 UTC (permalink / raw)
  To: zsh-users

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?

regards 

-- 
Marc Chantreux (eiro on github and freenode)
http://eiro.github.com/
http://eiro.github.com/atom.xml
"Don't believe everything you read on the Internet"
    -- Abraham Lincoln


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: (s,:,) made right ("" is also an element)
  2015-03-13 10:12 (s,:,) made right ("" is also an element) Marc Chantreux
@ 2015-03-13 10:42 ` Michal Politowski
  2015-03-13 14:16   ` Marc Chantreux
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Politowski @ 2015-03-13 10:42 UTC (permalink / raw)
  To: zsh-users

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: (s,:,) made right ("" is also an element)
  2015-03-13 10:42 ` Michal Politowski
@ 2015-03-13 14:16   ` Marc Chantreux
  0 siblings, 0 replies; 3+ messages in thread
From: Marc Chantreux @ 2015-03-13 14:16 UTC (permalink / raw)
  To: zsh-users

> print -l "${(@s,:,)PATH}"

arggh ... i was so close! (tried things like "${(s,:,)PATH[@]}") 

> It's described in the manual: 

"Parameter Expansion Flags" section! right! thank you to point it...

regards 


-- 
Marc Chantreux (eiro on github and freenode)
http://eiro.github.com/
http://eiro.github.com/atom.xml
"Don't believe everything you read on the Internet"
    -- Abraham Lincoln


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-13 14:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-13 10:12 (s,:,) made right ("" is also an element) Marc Chantreux
2015-03-13 10:42 ` Michal Politowski
2015-03-13 14:16   ` Marc Chantreux

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).