加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

在ZSH中设置环境变量给出了预期的数量

发布时间:2020-12-14 01:15:21 所属栏目:Linux 来源:网络整理
导读:我正在尝试在ZSH中设置一个数组(使用oh-my-zsh配置). export AR=(localhost:1919 localhost:1918) 但我得到一个像这样的错误: zsh: number expected 如果我不添加导出命令,那就没问题了.我没有在* rc文件中输入上述内容,只是在zsh提示符中.可能是什么问题呢
我正在尝试在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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读