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

Re: Exporting arrays

Andrew Main wrote:

[ snip ]

> Btw, it's impossible to export an array.  Unix environment variables are
> only strings.  There are ways an array could be encoded as a string,
> but some other shells get very unhappy about apparently malformed
> environment entries.
> -zefram

As a workaround, you could convert the array into a word list, using a
suited delimiter:

   a=(one two three four)
   export aex=${(j(:))a}

Then, in the subshell, convert the list back into an array:


Unfortunately this doesn't work if an array element is empty! Example:

   a=(one '' three four)
   export aex=${(j(:))a}   # aex=one::three:four
   # ...
   a=(${(s(:))aex})        # a=(one three four), $#a == 3

I reported this (IMHO) bug already some weeks ago. Has anybody tried to
fix it? I wasn't able yet to localize it in the sources.


Bernd Eggink
Regionales Rechenzentrum der Uni Hamburg

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