【问题标题】:How to set environment variable with dot in name using powershell?如何使用powershell在名称中设置带点的环境变量?
【发布时间】:2018-08-10 10:37:58
【问题描述】:

我想在名称中有点的 powershell 中设置环境变量。 此行抛出错误:

$env:Test.Env.Var1 = "test111"

The property 'Var1' cannot be found on this object. Verify that the property exists and can be set.
At line:1 char:1
+ $env:Test.Env.Var1 = "test111"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

是否可以在不使用[Environment]::SetEnvironmentVariable 方法的情况下设置“Test.Env.Var1”变量?

【问题讨论】:

  • ${env.test.value} = 'value'
  • “逗号”是指点吗?

标签: powershell


【解决方案1】:

这可以通过

${env:test.value} = 'value'

注意env 后面的冒号。这适用于powershellpwsh

参照。 https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_variables?view=powershell-7.2#variable-names-that-include-special-characters

【讨论】:

    【解决方案2】:

    可以这样做

    ${env:Test.Env.Var1} = 'value'

    source

    感谢@4c74356b41 在评论中提供答案。

    【讨论】:

      猜你喜欢
      • 2010-09-23
      • 2011-06-06
      • 2020-09-29
      • 2010-11-30
      • 1970-01-01
      • 1970-01-01
      • 2020-05-09
      • 1970-01-01
      • 2016-01-11
      相关资源
      最近更新 更多