我已经在 Ubuntu 20.10 上安装了 PowerShell,我正在尝试在终端上使用它,但它似乎不知道环境变量。如何让 PowerShell 知道 Ubuntu 上的环境变量?
问问题
81 次
1 回答
0
Write-Host $Env:PATH
是如何在 Linux 中从 Powershell 访问环境变量的示例。注意:变量名区分大小写。
如果你想看到Powershell可以“看到”的变量,
Get-ChildItem Env:
- 这将获取导出到环境的变量。它不会获取会话本地的变量。
如果您printenv
从 Ubuntu 运行,您将看到导出到环境中的所有变量 - 如上所述,Powershell 可以使用这些变量。
如果您set
从 Ubuntu 运行,您将看到所有变量(环境和 shell 变量)。要使其在 Powershell 中可用,您需要将其导出:
export x=$someshellvariable
pwsh
PS /mnt/c/git> Get-ChildItem $Env:x
Name Value
---- -----
x test
于 2021-02-26T12:58:25.890 回答