powershell - PowerShell:什么样的关键字 ist env: ?这样一个关键字的含义?
问题描述
要在 PowerShell 中显示所有环境变量,请使用:
Get-ChildItem env:
什么是'env:'?
我很清楚它是“环境”的缩写。但是什么样的缩写呢?最后的冒号是什么意思?
解决方案
您的查询在 PowerShell 帮助文件中定义:
关于自动变量:
$env 是上述的虚拟驱动器。通过以下内容很容易看到,其目的是允许访问上述内容:
# These are treated as normal filesystem drives, and you can create custom ones.
Get-PSDrive
<#
Name Used (GB) Free (GB) Provider Root CurrentLocation
---- --------- --------- -------- ---- ---------------
Alias Alias
C 5.04 34.83 FileSystem C:\ Scripts
Cert Certificate \
Env Environment
Function Function
HKCU Registry HKEY_CURRENT_USER
HKLM Registry HKEY_LOCAL_MACHINE
Variable Variable
WSMan WSMan
#>
Get-ChildItem -Path 'env:\'
<#
Using these in code requires the $ in front of each named variable to get the content/values. In your scripts, never name your custom variables the same as any of the below.
Name Value
---- -----
ALLUSERSPROFILE C:\ProgramData
APPDATA C:\Users\WDAGUtilityAccount\AppData\Roaming
CLIENTNAME 8fda9520-99a6-4
CommonProgramFiles C:\Program Files\Common Files
CommonProgramFiles(x86) C:\Program Files (x86)\Common Files
CommonProgramW6432 C:\Program Files\Common Files
COMPUTERNAME 0C092C31-6890-4
...
#>
如果您确实想使用上面的名称作为其他值的自定义变量,那么您应该提供一个唯一的前缀。说,您的姓名缩写,以免发生冲突/错误。
推荐阅读
- reactjs - reactJS 路由,错误 500 和 .htaccess:重写规则不适用于子路由
- database - 在每次提交时使用带有部署的数据库
- git - 如何同时对 repo 和子模块进行 Git 结帐?
- docker - Docker 构建命令在詹金斯中引发错误
- qaf - Qmetry - 如何更新 .wsc 文件中 api 请求键的值
- javascript - Wordpress – 指向日期过滤器元素的链接未添加到基本 url 并应用过滤器
- user-interface - 语音输入后提交按钮变得不可见(Web Speech API)
- c++ - 未找到 Gtest 入口点
- java - 从活动 A 移动到活动 B 并从活动 B 移动到活动 A
- java - 使用 ConfigurationProperties 自动装配抽象配置