Setting an environment variable in ZSH gives the expected number

I am trying to install an array in ZSH (configured using oh-my-zsh).

export AR=(localhost:1919 localhost:1918) 

but I get this error:

 zsh: number expected 

If I do not add the export command, this is just fine. I do not write above in the * rc file, just in the zsh request. What could be the problem?

+4
source share
1 answer

You cannot export array in zsh.

For more information: http://zsh.sourceforge.net/Guide/zshguide02.html

Please note that you cannot export arrays. If you export a parameter, then assign an array to it, nothing will appear in the environment; you can use the external printenv VARNAME' (again no command printenv VARNAME' (again no $', because the command must know the name, not the value) to check. There is a more subtle problem with arrays. Inline export is just a special case of an inline set that defines a variable without labeling it for export to the environment. You might think you could do

 typeset array=(this doesn\'t work) 

but you cannot understand the syntax of an array only when the assignment does not follow the command, and not in ordinary arguments, for example, here, so you need to put the assignment of the array on the next line. This is a very simple mistake to make. More use of the kit will be described in chapter 3; They include creating local parameters in functions and defining special attributes (attribute "export" is one) for Parameters.

+7
source

Source: https://habr.com/ru/post/1497379/


All Articles