New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.bashrc file didn't load when start bash in windows #2067

Closed
yhvicey opened this Issue May 6, 2017 · 13 comments

Comments

Projects
None yet
7 participants
@yhvicey
Member

yhvicey commented May 6, 2017

First, I entered WSL but it looks abnormally - no color and alias:

Abnormally bash

And if I enter bash again everything goes to work normally:

Normally bash

So what's wrong with my WSL? How to recover it? Thanks.

@sunjoong

This comment has been minimized.

Show comment
Hide comment
@sunjoong

sunjoong May 6, 2017

@yhvicey - ll is an alias in ~/.bashrc file like this; alias ll='ls -alF'. I guess bash.exe just spawn /bin/bash process, not reading ~/.bashrc file. Try this;

  • You can find bash.exe shortcut named Bash on Ubuntu on Windows in "C:\Users\sunjoong\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" directory; sunjoong is my username, so it might be yhvicey in yours.

  • The property of that shortcut is;

C:\Windows\System32\bash.exe ~

  • Change that like this;

C:\Windows\System32\bash.exe ~ -l

Option -l means like LOGIN; it's lowercase of L, not capital of i. Then, bash will read ~/.profile file and ~/.profile file read ~/.bahrc file.

sunjoong commented May 6, 2017

@yhvicey - ll is an alias in ~/.bashrc file like this; alias ll='ls -alF'. I guess bash.exe just spawn /bin/bash process, not reading ~/.bashrc file. Try this;

  • You can find bash.exe shortcut named Bash on Ubuntu on Windows in "C:\Users\sunjoong\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" directory; sunjoong is my username, so it might be yhvicey in yours.

  • The property of that shortcut is;

C:\Windows\System32\bash.exe ~

  • Change that like this;

C:\Windows\System32\bash.exe ~ -l

Option -l means like LOGIN; it's lowercase of L, not capital of i. Then, bash will read ~/.profile file and ~/.profile file read ~/.bahrc file.

@yhvicey

This comment has been minimized.

Show comment
Hide comment
@yhvicey

yhvicey May 6, 2017

Member

@sunjoong After installation there is no short cut in start menu so I created one manually:

My shortcut

After adding "-l" to target I tried again but still doesn't work. I guess it has nothing to do with shortcut because there's same issue if I start %WINDIR%\System32\Bash.exe directly.

And this problem seems to appear in recent insider builds. Or, I have changed the color of the bash console. Does it matters?

Member

yhvicey commented May 6, 2017

@sunjoong After installation there is no short cut in start menu so I created one manually:

My shortcut

After adding "-l" to target I tried again but still doesn't work. I guess it has nothing to do with shortcut because there's same issue if I start %WINDIR%\System32\Bash.exe directly.

And this problem seems to appear in recent insider builds. Or, I have changed the color of the bash console. Does it matters?

@sunjoong

This comment has been minimized.

Show comment
Hide comment
@sunjoong

sunjoong May 6, 2017

@yhvicey - Something's wrong!!

  1. Shortcut should exist.
  2. ~/.bashrc file should be read even without any options.
  3. ~/.profile file should be read with -l option.

I meant -l option, not shortcut. Sorry, I have no idea but know something's wrong in recent insider builds.

sunjoong commented May 6, 2017

@yhvicey - Something's wrong!!

  1. Shortcut should exist.
  2. ~/.bashrc file should be read even without any options.
  3. ~/.profile file should be read with -l option.

I meant -l option, not shortcut. Sorry, I have no idea but know something's wrong in recent insider builds.

@yhvicey

This comment has been minimized.

Show comment
Hide comment
@yhvicey

yhvicey May 6, 2017

Member

@sunjoong

  1. Due to poor network I download install package manually and install it by hooking network request by Fiddler, I guess that's why I don't have a shortcut.
  2. It seems that my bash didn't execute ~/.bashrc when I open it, neither through shortcut nor open it directly.
  3. Thanks for you information.
Member

yhvicey commented May 6, 2017

@sunjoong

  1. Due to poor network I download install package manually and install it by hooking network request by Fiddler, I guess that's why I don't have a shortcut.
  2. It seems that my bash didn't execute ~/.bashrc when I open it, neither through shortcut nor open it directly.
  3. Thanks for you information.

@yhvicey yhvicey changed the title from Why do I have to enter WSL twice to make it work normally? to .bashrc file didn't load when start bash in windows May 6, 2017

@sunjoong

This comment has been minimized.

Show comment
Hide comment
@sunjoong

sunjoong May 6, 2017

@yhvicey - This is not a solution becasue that not reading ~/.bashrc file issue might not removed, but... you said runnig /bin/bash manually worked, so... it might be an emegency trick, I think.

Try -c /bin/bash like this;

C:\Windows\System32\bash.exe ~ -c /bin/bash

sunjoong commented May 6, 2017

@yhvicey - This is not a solution becasue that not reading ~/.bashrc file issue might not removed, but... you said runnig /bin/bash manually worked, so... it might be an emegency trick, I think.

Try -c /bin/bash like this;

C:\Windows\System32\bash.exe ~ -c /bin/bash

@yhvicey

This comment has been minimized.

Show comment
Hide comment
@yhvicey

yhvicey May 6, 2017

Member

@sunjoong It works, thanks for your workaround.

Member

yhvicey commented May 6, 2017

@sunjoong It works, thanks for your workaround.

@0xbadfca11

This comment has been minimized.

Show comment
Hide comment
@0xbadfca11

0xbadfca11 May 6, 2017

Before than 16184, bash's argv[0] is '/bin/bash'. This is non-login shell. Bash will only loads .bashrc.
Starting 16184, bash's argv[0] is '-bash'. This is login shell. Bash loads only the first one in .bash_profile or .bash_login or .profile. Don't see .bashrc. However, the default .profile will executes .bashrc.
Let's load .bashrc yourself when using .bash_profile or .bash_login which has higher priority than .profile.
Even if '-l' is added, .bashrc is not loaded because there are files with higher priority than .profile.

0xbadfca11 commented May 6, 2017

Before than 16184, bash's argv[0] is '/bin/bash'. This is non-login shell. Bash will only loads .bashrc.
Starting 16184, bash's argv[0] is '-bash'. This is login shell. Bash loads only the first one in .bash_profile or .bash_login or .profile. Don't see .bashrc. However, the default .profile will executes .bashrc.
Let's load .bashrc yourself when using .bash_profile or .bash_login which has higher priority than .profile.
Even if '-l' is added, .bashrc is not loaded because there are files with higher priority than .profile.

@sunjoong

This comment has been minimized.

Show comment
Hide comment
@sunjoong

sunjoong May 6, 2017

@0xbadfca11 - Thanks for notice; that's very important news.
@yhvicey - You have ~/.bash_profile and ~/.profile both, but ~/.bash_profile would be read if bash be a login shell and you have ~/.bash_profile. Check your ~/.bash_profile to have these lines;

if [[ -f ~/.bashrc ]] ; then
	. ~/.bashrc
fi

You might find simular thing in ~/.profile but you have ~/.bash_profile, so check that file.

sunjoong commented May 6, 2017

@0xbadfca11 - Thanks for notice; that's very important news.
@yhvicey - You have ~/.bash_profile and ~/.profile both, but ~/.bash_profile would be read if bash be a login shell and you have ~/.bash_profile. Check your ~/.bash_profile to have these lines;

if [[ -f ~/.bashrc ]] ; then
	. ~/.bashrc
fi

You might find simular thing in ~/.profile but you have ~/.bash_profile, so check that file.

@yhvicey

This comment has been minimized.

Show comment
Hide comment
@yhvicey

yhvicey May 6, 2017

Member

@0xbadfca11 Thank you very much. I have created a .bash_profile file to disable bell before.
@sunjoong These codes are in my ,profile file and I'll merge these files to solve this. Thanks for your help.

Member

yhvicey commented May 6, 2017

@0xbadfca11 Thank you very much. I have created a .bash_profile file to disable bell before.
@sunjoong These codes are in my ,profile file and I'll merge these files to solve this. Thanks for your help.

@tito433

This comment has been minimized.

Show comment
Hide comment
@tito433

tito433 Sep 14, 2017

@sunjoong , I was having the same problem. Your code solved mine.

tito433 commented Sep 14, 2017

@sunjoong , I was having the same problem. Your code solved mine.

@ChaosFreak

This comment has been minimized.

Show comment
Hide comment
@ChaosFreak

ChaosFreak Dec 3, 2017

@sunjoong Your answer is perfect! It fixed it for me.

ChaosFreak commented Dec 3, 2017

@sunjoong Your answer is perfect! It fixed it for me.

@vunb

This comment has been minimized.

Show comment
Hide comment
@vunb

vunb Jan 3, 2018

@sunjoong It works for me. Thanks!

vunb commented Jan 3, 2018

@sunjoong It works for me. Thanks!

@r4k0nb4k0n

This comment has been minimized.

Show comment
Hide comment
@r4k0nb4k0n

r4k0nb4k0n Jan 14, 2018

@sunjoong Thank you for your answer!

r4k0nb4k0n commented Jan 14, 2018

@sunjoong Thank you for your answer!

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