DEV Community

Cover image for Kept running "source .bashrc" every time I open WSL
Eden Jose
Eden Jose

Posted on • Updated on

Kept running "source .bashrc" every time I open WSL

I was playing around and testing some stuff in Linux when i suddenly did a tweak which changed how my WSL terminal opens up. This is what my terminal looks like - notice it doesn't the distinct green + blue colors.

After some searching I found two articles (links at the bottom) which describes the "sequence" which Unix follows when reading files. As summary, here's the files (in order):

  1. /etc/profile
  2. ~/.bash_profile
  3. ~/.bash_login 4 ~/.profile

I added the function for .bashrc at the top of the .bash_profile:

## Loads .bashrc
if [[ -f ~/.bashrc ]] ; then
        . ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Closed terminal and reopened it
Voila! It now shows the green and blue colors.

Adding this great explanation from the reference link:

By default, Terminal starts the shell via /usr/bin/login, which makes the shell a login shell. On every platform (not just Mac OS X) bash does not use .bashrc for login shells (only /etc/profile and the first of .bash_profile, .bash_login, .profile that exists and is readable). This is why "put source ~/.bashrc in your .bash_profile" is standard advice


Discussion (0)