windows环境变量名可以带点吗? [英] Is it allowed to have windows environment variable name to have dot?

查看:42
本文介绍了windows环境变量名可以带点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 Windows 平台的 powershell 中将环境变量设置为 aaa.bbb 但它看起来不像 ..

I tried to set environment variable as aaa.bbb in powershell from windows platform however it looks like it does not like ..

这有效.

$Env:aaa = "testvalue"

这失败了.

$Env:aaa.bbb = "testvalue2"

环境变量名可以有.吗?

推荐答案

您可以将所需的变量括在括号中,如下所示:

You can set the desired variable by enclosing it in brackets like this:

${Env:aaa.bbb} = "testvalue2"

请注意,您需要通过包含括号来引用变量,但制表符补全会有所帮助(至少在 PowerShell 5.1 上).

Note that you'll need to reference the variable by including the brackets but tab completion helps(at least on PowerShell 5.1).

eryksun 提到的 New-Item/Set-Item 在外观上稍微不那么杂乱:

Slightly less cluttered in appearance is the New-Item/Set-Item as mentioned by eryksun:

New-Item -Path Env:aaa.bbb -Value "testvalue2"

我看到选项 [Environment]::SetEnvironmentVariable 根据评论,Jeroen Mostert 为您提供了解决方案.

I see the option [Environment]::SetEnvironmentVariable Jeroen Mostert provided has done the trick for you, per the comments.

这篇关于windows环境变量名可以带点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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