Ubuntu – How to set environment variables from within powershell

bashdotnetenvironment-variablespowershellscripts

How do I make foo an environment variable accessible through printenv on bash?

PS /home/thufir/powershell/helloPSTwitterAPI> 
PS /home/thufir/powershell/helloPSTwitterAPI> $env:foo = 'x' * 333 + '!'      
PS /home/thufir/powershell/helloPSTwitterAPI> 
PS /home/thufir/powershell/helloPSTwitterAPI> $env:foo
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx!
PS /home/thufir/powershell/helloPSTwitterAPI> 

I would like to use powershell to set an environment variable rather than using setenv itself so that Visual Studio Code, and bash, will pick up the variables when running powershell scripts.

Best Answer

I would do it as described below:

[System.Environment]::SetEnvironmentVariable('DOCKER_HOST','docker.artofshell.com')

See also

This way the environment variable (in this case DOCKER_HOST) is created permanently as if you would've created it via the windows control panel.

Related Question