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

Re: parameter expansion question



On Jan 18,  1:28am, Szekeres Istva'n wrote:
> 
> #this is NOT ok, it prints 1=a 2=b 3=
> foo='a::b'
> print_em ${(s/:/)foo}
> 
> It seems like in the second case the empty string is not passed as the
> 2nd parameter. How to specify the expansion so it will pass the empty
> string just like in the first example?

You have two problems.

The first is that the (s) flag always collapses consecutive occurrences
of the split character; unlike perl's split function, zsh's (s/:/) cannot
create an empty word in the middle of "::".

Even if that worked, though, empty arguments are deleted when not quoted,
so you would need to quote the parameter expansion.

As a workaround to the splitting problem, you can use "typeset -T" like
so:
	typeset -T foo splitfoo :

And then quote the expansion:
	print_em "$splitfoo[@]"

Note that it doesn't work properly to use "typeset -T" more than once on
the same scalar variable (that is, you can't tie the same scalar to more
than one array).



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