如何导出点分隔的环境变量

如何导出点分隔的环境变量

本文介绍了如何导出点分隔的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的执行

user@EWD-MacBook-Pro:~$ export property.name=property.value

给我

-bash: export: `property.name=property.value': not a valid identifier

是否有可能与点内系统属性?如果是的话该怎么办?

Is it possible to have system properties with dot inside? If so how do that?

推荐答案

正如其他人所说,bash将不允许它,所以你将不得不使用自己喜欢的脚本语言来做到这一点。例如,在Perl:

As others have said, bash doesn't allow it so you'll have to use your favourite scripting language to do it. For example, in Perl:

perl -e '$ENV{"property.name"} = "property.value"; system "bash"'

这会火起来的 property.name 环境变量设置子shell bash的,但你还是不能从bash的访问环境变量(虽然你的程序将是能够看到它)。

This will fire up a subshell bash with the property.name environment variable set, but you still can't access that environment variable from bash (although your program will be able to see it).

修改:@MarkEdgar评论说, ENV 命令也可以工作:

Edit: @MarkEdgar commented that the env command will work too:

 env 'property.name=property.value' bash # start a subshell, or
 env 'property.name=property.value' command arg1 arg2 ...   # Run your command

像往常一样,你只有当你需要保护的特殊字符从壳或希望包括在属性名称或值空间需要引号。

As usual, you only require quotes if you need to protect special characters from the shell or want to include spaces in the property name or value.

这篇关于如何导出点分隔的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 08:31