How can I make PowerShell get environmental variables on Ubuntu 20.10?

927 Views Asked by At

I have installed PowerShell on Ubuntu 20.10 and I'm trying to use it on terminal but it does not seem to know the environmental variables. How can I make PowerShell know the environmental variables on Ubuntu?

1

There are 1 best solutions below

2
On

Write-Host $Env:PATH is an example of how to access an environment variable from Powershell in Linux. Note: the variable names are case sensitive.

If you want to see the variables that Powershell can "see",

Get-ChildItem Env: - this gets variables that are exported to the enviroment. It will not get variables that are local to the session.

If you run printenv from Ubuntu, you'll see all of the variables exported to the enviroment - these will be available to Powershell as indicated above.

If you run set from Ubuntu, you'll see all variables (enviromnent and shell variables). To make it available from Powershell, you will need to export it:

export x=$someshellvariable
pwsh
PS /mnt/c/git> Get-ChildItem $Env:x

Name                           Value
----                           -----
x                              test