Provide a way to set environment variables when launching bash
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.
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):
bash -c "bash -c 'source /LINUX_PATH_TO_FILE_WITH_VARIABLES'"
Or to load default bash variables just simply type:
bash -c "bash"
You can make .bat file as a shortcut:
echo bash -c "bash" > bash_with_default_variables.bat
or
echo bash -c "bash -c 'source /LINUX_PATH_TO_FILE_WITH_VARIABLES' > bash_with_custom_variables.bat
If you're looking for additional support, I suggest adding something over to our UserVoice page.
Additionally I'd suggesting adding any additional environment variables you need to you .bashrc file.
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.
I guess the existing solutions are good enough.
With WSL on Windows 10 Creators Update you can use this command:
C:\Windows\System32\bash.exe ~ --login
and then edit .profile in your home directory.
@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_variables
@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.