Split string with zsh as in Python

Posted by Olivier on Stack Overflow See other posts from Stack Overflow or by Olivier
Published on 2010-05-28T15:21:54Z Indexed on 2010/05/30 18:02 UTC
Read the original article Hit count: 254

Filed under:
|
|

In python:

s = '1::3'
a = s.split(':')
print a[0] # '1' good
print a[1] # '' good
print a[2] # '3' good

How can I achieve the same effect with zsh?

The following attempt fails:

s="1::3"
a=(${(s/:/)s})
echo $a[1] # 1
echo $a[2] # 3 ?? I want an empty string, as in Python

© Stack Overflow or respective owner

Related posts about string-manipulation

Related posts about split