You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide a way to set environment variables when launching bash #219
There should be a way to pass some environment variables from the Win32 bash.exe launcher to the launched bash WSL process. One use case would be for example to set BASH_ENV to custom values for each non interactive invocation of bash. Of course there are plenty of other useful environment variables depending on the tool being targeted, so the most useful would be a generic way to specify which variable to pass and/or to override.
Because the Windows PATH, for instance, has nothing to do with the WSL PATH, this cannot just be a list of variables to copy from the Windows environment using the same name. Full new name=values would have to be specified on the command line with a special option. Another idea would be a special prefix that would be stripped, for example Windows environments variables _WSL_NAME=VALUE would become NAME=VALUE under WSL.
Reacted by Timur Sharifianov, Abhishek GS, nidea4u, spray and tioteath
Antonio Barta (@hapihakr) Where's the --login argument documented? The --help doesn't say anything about what that argument does and it's not doing anything extra from what I can tell. My .profile is unchanged and I have no Windows environment variables in bash.
Activity
patryk9200 commentedon Apr 18, 2016
It's possible.
I made instruction how to do this here:
#24
You can make this if you want set additional variables (run this in cmd.exe):
Or to load default bash variables just simply type:
You can make .bat file as a shortcut:
or
russalex commentedon Apr 18, 2016
If you're looking for additional support, I suggest adding something over to our UserVoice page.
benhillis commentedon Apr 19, 2016
Additionally I'd suggesting adding any additional environment variables you need to you .bashrc file.
xilun commentedon Apr 19, 2016
Well it was more about dynamically assigning environment variables without creating extra processes or files.
If creating a new file is tolerated, I also found a solution with --rcfile for interactive shells.
xilun commentedon Apr 19, 2016
I guess the existing solutions are good enough.
hapihakr commentedon Apr 17, 2017
With WSL on Windows 10 Creators Update you can use this command:
C:\Windows\System32\bash.exe ~ --loginand then edit .profile in your home directory.
thesmart commentedon Dec 7, 2017
Ben Hillis (@benhillis) Your suggestion confuses system and per-user environments. This isn't great when trying to replicate server environments where multiple processes might run as different users but have the same PATH set by
/etc/environment. This is Ubuntu 101 stuff, not sure how WSL can claim to be "Ubuntu" but not support system environment: https://help.ubuntu.com/community/EnvironmentVariables#System-wide_environment_variablessw-carlin commentedon Dec 7, 2017
Antonio Barta (@hapihakr) Where's the
--loginargument documented? The--helpdoesn't say anything about what that argument does and it's not doing anything extra from what I can tell. My .profile is unchanged and I have no Windows environment variables in bash.