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

Re: Exporting arrays



Adam Spiers wrote:
>% foo=(a b c)
>% typeset | grep zzz
>array foo=(a b c)
>% export foo=(a b c)
>% typeset | grep zzz 
>array exported foo=(a b c)
>
>However,
>
>% unset foo
>% export foo=(a b c)
>% typeset | grep zzz 
>exported foo='(a b c)'

This sort of thing has cropped up before, and it has always been due to
human error.  </hal>

In the case of "export foo=(a b c)", the parens do not actually delimit
an array.  They are treated as globbing metacharacters.  This command runs
the builtin "export", with argument "foo=(a b c)", which it interprets as
a request to export the variable "foo" and set its value to the scalar
"(a b c)".  In the second of your dialogues, that's precisely what
happens.  In the first dialogue, you first set foo to be an array,
and the export command refused to change it to a scalar.

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



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