-1

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?

Amani
  • 16,245
  • 29
  • 103
  • 153

1 Answers1

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