skip to Main Content

Until recently, when I’ve launched the integrated terminal in Visual Studio Code, bash runs both my .bashrc and my .bash_profile files. But now it’s only running the .bashrc file. I need it to run both.

Some details: VSC 1.70.1 (latest), with the "Remote – SSH" extension, running under Windows 10 (updated) with WSL 2 installed. When I launch a Microsoft terminal, it runs both .bashrc and .bash_profile, but VSC’s integrated terminal only runs the former. This probably means I have s.t. wrong in my VSC config, but the settings there seem to change frequently and it’s hard to keep up. The relevant parts seem to be

"terminal.integrated.defaultProfile.windows": "WSL",
"terminal.integrated.profiles.windows": {
    "bash":{
           "path": "C:\Windows\System32\bash.exe",
           "args": ["-l"]
    },
    "WSL": {
           "path": "C:\WINDOWS\System32\wsl.exe",
           "args": [ ],
           "icon": "terminal-ubuntu"
    }
},

but that doesn’t work, nor do any of the variants I’ve tried on the two "args" parameters, nor changing the defaultProfile to "bash" instead of "WSL".

Before I give in and put all my startup settings in my .bashrc file and get rid of my .bash_profile file, what do I yet lack?

2

Answers


  1. I can’t reproduce this after even after upgrading to 1.70.1, so I’d recommend trying out these things:

    • try

       "path": "C:\WINDOWS\System32\wsl.exe",
       "args": ["-e", "bash", "-li"]
      

      to make sure that a login shell is started

    • if this changed after upgrading, read Help -> Release Notes to find out what might be responsible, e.g. the Shell integration is now enabled by default, so you might try "terminal.integrated.shellIntegration.enabled": false

    • sync / backup your settings, re-install vanilla VSC, check if behaviour is still the same

    Login or Signup to reply.
  2. The historical presumption on UNIX is that .bash_profile runs once when you log in, then .bashrc runs in each new shell. Thus, things that are inherited by child processes (like environment variables) go in .bash_profile so they can only run once per login (often, as a parent process to xinit or otherwise GUI startup), whereas things that need to be separately configured for each new shell (like aliases, non-exported functions, prompt settings, etc) go in .bashrc.

    If, however, you’re in an environment where .bash_profile isn’t run during session creation, you might want to invoke it during .bashrc operation (so it happens during setup of any new interactive shell). Consider adding the following to your .bash_profile:

    # put this at the top of your .bash_profile
    [[ $profile_already_sourced ]] && return
    declare -x profile_already_sourced=1 # export so we only run once per process tree
    
    # ...set up your environment variables here...
    
    [[ -s ~/.bashrc ]] && source ~/.bashrc
    

    …and the following to your .bashrc:

    # put this at the top of your .bashrc
    [[ $bashrc_already_sourced ]] && return
    declare -- bashrc_already_sourced=1 # do not export this!
    
    # ...do your non-exported shell-local configuration here...
    
    [[ -s ~/.bash_profile ]] && source ~/.bash_profile
    

    …that way you can have each file source the other when needed without causing an infinite loop.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search