-2

我已经在 Ubuntu 20.10 上安装了 PowerShell,我正在尝试在终端上使用它,但它似乎不知道环境变量。如何让 PowerShell 知道 Ubuntu 上的环境变量?

4

1 回答 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 回答