为什么将数组字符串(带有括号)分配给环境变量不起作用 [英] Why the assignment of an array string (with brackets) to environment variable is not working

查看:41
本文介绍了为什么将数组字符串(带有括号)分配给环境变量不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在bash shell中执行以下命令:

Execute the following command in bash shell:

export sz1='"authorities" : ["uaa.resource"]'

现在,尝试 echo $ sz1

我希望看到以下输出:

"authorities" : ["uaa.resource"]

但是我得到了:

"authorities" : c

有趣的是,我有数十台服务器可以在其中执行这种类型的变量赋值,并且除此服务器外都可以运行.该服务器具有完全相同的OS版本,配置文件,bash版本等.这种现象可能是什么原因?

The interesting thing is that I have dozens of servers where I can execute this type of variable assignment and it works except on this server. This server has exactly the same OS version, profile, bash version etc. What could be the reason for this behavior?

推荐答案

始终引用变量.使用

echo "$sz1"

不引用变量时,将在变量扩展上进行单词拆分和通配符扩展.在 ["uaa.resource"] 上是一个通配符,它​​将匹配以下任何文件名:

When you don't quote the variable, word splitting and wildcard expansion is done on the variable expansion. On ["uaa.resource"] is a wildcard that will match any of the following filenames:

"
u
a
.
r
e
s
o
u
c

在那台机器上,您有一个名为 c 的文件,因此通配符匹配并被该文件名替换.

On that one machine you have a file named c, so the wildcard matches and gets replaced with that filename.

这篇关于为什么将数组字符串(带有括号)分配给环境变量不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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