Skip to content

Provide a way to set environment variables when launching bash #219

Closed

Description

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.

Activity

  1. patryk9200 commented on Apr 18, 2016

    @patryk9200

    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

  2. russalex commented on Apr 18, 2016

    @russalex
    Contributor

    If you're looking for additional support, I suggest adding something over to our UserVoice page.

  3. benhillis commented on Apr 19, 2016

    @benhillis
    Member

    Additionally I'd suggesting adding any additional environment variables you need to you .bashrc file.

  4. xilun commented on Apr 19, 2016

    @xilun
    Author

    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.

  5. xilun commented on Apr 19, 2016

    @xilun
    Author

    I guess the existing solutions are good enough.

  6. hapihakr commented on Apr 17, 2017

    @hapihakr

    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.

  7. thesmart commented on Dec 7, 2017

    @thesmart

    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_variables

  8. sw-carlin commented on Dec 7, 2017

    @sw-carlin

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions