0

I recently: Specified a home directory path for a user in /etc/passwd with spaces in it? but now my .bashrc doesn't source properly when I open a Ubuntu 16.04 LTS WSL window, so I have to source it manually...which works with source ~/.bashrc, but curiously does not work with source $HOME/.bashrc, but oddly does work with source "$HOME"/.bashrc.

So Jeff on the previous question thought that maybe the issue is that something else is sourcing it without the quotes around it.

In fact a similar issue caused me to fork git hub project in which a similar error was occurring; I attributed it to be because I was using mingw64 / git-bash for Windows, but that wasn't the issue at all because now it's occurring in WSL...er at least I think that's the case...

6
  • 1
    don't you think the problem is simply word-splitting of the unquoted $HOME? – Jeff Schaller Sep 18 '19 at 18:40
  • @JeffSchaller Yes, but my question is what is running it when I open my terminal, so I can fix the issue there? Because I can't re-export $HOME unless I'm using .bashrc to do that. – leeand00 Sep 18 '19 at 18:48
  • Sorry, I got hung up on your test of source $HOME/.bashrc which failed. Your actual question is centered around whatever's calling it that way. – Jeff Schaller Sep 18 '19 at 18:50
  • @Gilles I have a couple of different windows up, and I get different outputs (I guess this is from different things I changed in /etc/passwd as at one point I tried to set the user's login shell to tmux; the one that has tmux running when I run $- gives me smi. There are two other ones which don't appear to have tmux running and the one gives me himBH and the other one has vim running (without tmux) and that one reads hBc when I run $- – leeand00 Sep 18 '19 at 20:05
  • @Gilles The fresh one I opened also reads himBH when I run $- – leeand00 Sep 18 '19 at 20:06
5

curiously does not work with source $HOME/.bashrc

That's normal: it isn't supposed to work. source "$HOME/.bashrc" runs instructions from the file .bashrc in your home directory, but source $HOME/.bashrc takes the path to .bashrc, splits it at whitespace, and runs instructions from the file whose name is the part up to the first space and uses the other parts as positional arguments (available as "$@" from code in .bashrc). (That's assuming there are no wildcards in the value of HOME.)

Normally nothing would run a command like source ~/.bashrc: bash already does this when it starts. A likely explanation is that the WSL window runs a login shell. When bash is a login shell, it doesn't load .bashrc, it loads .bash_profile or .profile instead. Most people work around this quirk by sourcing .bashrc from .bash_profile. Check your .bash_profile (or if you don't have one your .profile, they might have the erroneous source $HOME/.bashrc or . $HOME/.bashrc instead of one of the correct methods (source ~/.bashrc, or if you like being verbose source "$HOME/.bashrc", or either of these with . instead of source).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.