在 ZSH 中设置环境变量给出预期的数字 [英] Setting environment variable in ZSH gives number expected

查看:196
本文介绍了在 ZSH 中设置环境变量给出预期的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 ZSH 中设置一个数组(使用 oh-my-zsh 配置).

I'm trying to set an array in ZSH (configured using oh-my-zsh).

export AR=(localhost:1919 localhost:1918)

但我收到这样的错误:

zsh: number expected

如果我不加export命令就好了.我没有在 *rc 文件中输入以上内容,只是在 zsh 提示中输入.可能是什么问题?

If I don't add the export command, it's just fine. I'm not typing the above in a *rc file, just in the zsh prompt. What could be the problem?

推荐答案

你不能在 zsh 中export一个数组.

You can't export an array in zsh.

更多信息:http://zsh.sourceforge.net/Guide/zshguide02.html

请注意,您不能导出数组.如果导出参数,则为其分配一个数组,环境中不会出现任何内容;你可以使用外部命令 printenv VARNAME(再次没有 $,因为命令需要知道名称,而不是值)来检查.有一个数组也有更微妙的问题.导出内置只是一个内置排版的特例,它定义了一个没有将其标记为出口到环境中.你可能认为你可以做到

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

排版数组=(这不起作用)

但你不能——特别的数组语法仅在赋值不遵循命令,而不是像这里的情况这样的正常参数,所以你必须将数组赋值放在下一行.这是一个非常容易的错误使.排版的更多使用将在第 3 章中介绍;他们包括在函数中创建局部参数,以及定义特殊的属性(其中 export 属性只是其中之一)参数.

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.

这篇关于在 ZSH 中设置环境变量给出预期的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆