Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Windows environment variables directly in wsl shell without modifying bash environment #6747

Open
jmoguillansky-gpsw opened this issue Apr 1, 2021 · 5 comments
Labels

Comments

@jmoguillansky-gpsw
Copy link

Is your feature request related to a problem? Please describe.
Suppose the user wants to set windows environment variables from wsl.
In the current mechanism, the user needs to first set a bash environment variable, then export it as a windows environment variable via WSLENV. The problem is that this defines environment variables in the bash shell as well.
Suppose that the windows environment variable has the same name as a bash environment variable.
Currently it's impossible to set one value for bash shell, and a different value for windows environment.

For example:
suppose we want to set "TEMP" windows environment variable from wsl.
The user has to do:
export TEMP=...
export WSLENV=TEMP/w:...
The problem is that this will modify the value of TEMP environment variable in bash shell as well.

Describe the solution you'd like
We need some mechanism to set windows environment variables from wsl without modifying the bash environment.

Something like:
win_env_set TEMP = ...

Describe alternatives you've considered

Additional context

@therealkenc
Copy link
Collaborator

You probably want something like:

image

@jmoguillansky-gpsw
Copy link
Author

but that's in a child shell. as soon as powershell closes, the environment variable is gone.

@therealkenc
Copy link
Collaborator

The Windows environment set by WSLENV is "gone" too after the underlying Windows command exits. If you want to persist TEMP="foo", wrap the powershell.exe in a bash or python script, or a shell function in .bashrc. Parameterize the script to taste.

@jmoguillansky-gpsw
Copy link
Author

wsl lets us launch windows executables directly. It's nice if we can launch the windows executable directly, with various environment variables, instead of via a command shell or powershell child shell. WSLENV is useful because it let's us share bash environment variables with windows. But it would be more powerful if there was a mechanism to set windows environment variables without modifying the bash environment.

@jmoguillansky-gpsw jmoguillansky-gpsw changed the title setting windows environment variables from wsl Set Windows environment variables directly in wsl shell without modifying bash environment Apr 1, 2021
@0xbadfca11
Copy link

export TEMP=42
export WSLENV=TEMP/w
TEMP=63 cmd.exe /c echo %TEMP%
TEMP=99 cmd.exe /c echo %TEMP%
echo $TEMP
export TEMP=42
export WSLENV=TEMP/w
(
TEMP=63
cmd.exe /c echo %TEMP%
TEMP=99
cmd.exe /c echo %TEMP%
)
echo $TEMP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants