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

Re: var to Array conversion ?



Frank Terbeck <ft@xxxxxxxxxxxxxxxxxx>:
> Meino Christian Cramer <Meino.Cramer@xxxxxx>:
> >  In a shell script a variable foo is set to 2.0:3.5:0.2
> >    a=2.0:3.5:0.2
> >  is there a any short one liner to convert the contents of a into
> >  the contents which would result from an assignment like
> >    a=(2.0 3.5 0.2)
> 
> See 'man zshbuiltins' (the 'typeset' builtin, '-T' option).
> 
> Example:
> 
> [snip]
> # 3rd arg. to typeset -T is optional (default ':').
> typeset -T string array ':'
> string="one:two:three:four"
> array+=five
> print -l $array
> [snap]

Note, that if you really want conversion you can do it like this:

[snip]
string="one:two:three:four"
array=(${(s,:,)string})
print -l $array
[snap]

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925



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