我正在尝试在ZSH中设置一个数组(使用oh-my-zsh配置).
export AR=(localhost:1919 localhost:1918)
但我得到一个像这样的错误:
zsh: number expected
如果我不添加导出命令,那就没问题了.我没有在* rc文件中输入上述内容,只是在zsh提示符中.可能是什么问题呢?
您无法在zsh中导出数组.
欲了解更多信息:http://zsh.sourceforge.net/Guide/zshguide02.html
Note that you can’t export arrays. If you export a parameter,then
assign an array to it,nothing will appear in the environment; you can
use the external command printenv VARNAME' (again no
$’ because the
command needs to know the name,not the value) to check. There’s a
more subtle problem with arrays,too. The export builtin is just a
special case of the builtin typeset,which defines a variable without
marking it for export to the environment. You might think you could do
typeset array=(this doesn't work)
but you can’t — the special array syntax is only understood when the assignment does not follow a command,not in normal arguments like the case here,so you have to put the array assignment on the next line. This is a very easy mistake to make. More uses of typeset will be described in chapter 3; they include creating local parameters in functions,and defining special attributes (of which the `export’ attribute is just one) for parameters.