PowerShell中的环境变量名称中带有点(.) [英] Environment variables in PowerShell with a dot (.) in the name

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

问题描述

我知道我可以使用$Env访问PowerShell中的环境变量.例如,我可以使用$Env:FOO访问FOO.

I know I can access environment variables in PowerShell using $Env. For example, I can access FOO with $Env:FOO.

我不知道如何访问名为FOO.BAR的环境变量.

I can't figure out how to access the environment variable called FOO.BAR.

$Env:FOO.BAR不起作用.如何在PowerShell中访问它?

$Env:FOO.BAR doesn't work. How can I access this from within PowerShell?

推荐答案

要访问名称中包含非字母数字字符的任何类型的PowerShell变量,请使用$ {…}表示法,如下所示:

To access any kind of PowerShell variable where the name contains non-alphanumeric characters, use the ${…} notation as in:

${env:variable.with.dots} = "Hi there"
${env:variable.with.dots}

这适用于任何驱动器(注册表,文件系统等)中的变量

This works for variables in any drive (registry, filesystem, etc.)

这篇关于PowerShell中的环境变量名称中带有点(.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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