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?
Asked
Active
Viewed 702 times
-1
-
1That's like trying to run a python program with a javascript interpreter and expecting it to work... – Shawn Feb 26 '21 at 11:08
-
@Shawn OK, understood. How can PowerShell get environmental variables on Ubuntu? – Amani Feb 26 '21 at 11:24
-
bash -c env?... – Raman Sailopal Feb 26 '21 at 12:46
-
Powershell does support Linux. It *does* have quirks, but the basic support is there. – WaitingForGuacamole Feb 26 '21 at 12:59
1 Answers
0
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

WaitingForGuacamole
- 3,744
- 1
- 8
- 22
-
I've tried it and it give very few paths compared to what I know there is. I wonder where does PowerShell read these or how can I make it know what bash knows. – Amani Feb 26 '21 at 13:33
-
Updated answer - there's more behind variables and how they are supported in Powershell that should be taken into account. – WaitingForGuacamole Feb 26 '21 at 14:01