Skip to content
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 doesn't execute #191

Closed
kjeremy opened this issue Jun 11, 2015 · 26 comments · Fixed by git-for-windows/build-extra#71
Closed

.bashrc doesn't execute #191

kjeremy opened this issue Jun 11, 2015 · 26 comments · Fixed by git-for-windows/build-extra#71

Comments

@kjeremy
Copy link

kjeremy commented Jun 11, 2015

In trying to use git through ConsoleZ I invoke it with the following command: PathToGit\Git\git-cmd.exe --command=PathToGit\Git\usr\bin\bash.exe --login -i

Logging in this way does not execute the user's .bashrc.

@dscho
Copy link
Member

dscho commented Jun 11, 2015

Probably related to msysgit/msysgit#301.

@kjeremy
Copy link
Author

kjeremy commented Jun 15, 2015

Yes I think it is related. If I $ cp .bashrc .bash_profile then my aliases work.

@dscho
Copy link
Member

dscho commented Jun 17, 2015

@kjeremy so how about giving it a try? This commit would still need some work, but it should be straight-forward to address my feedback (and to adjust the commit message).

@dscho
Copy link
Member

dscho commented Jun 20, 2015

@kjeremy are you still interested in resolving this issue?

@kjeremy
Copy link
Author

kjeremy commented Jun 20, 2015

Sure. Hopefully I'll get some time to work on it next week. What exactly
was your issue with the commit that was proposed?

On Sat, Jun 20, 2015 at 11:50 AM, dscho notifications@github.com wrote:

@kjeremy https://github.com/kjeremy are you still interested in
resolving this issue?


Reply to this email directly or view it on GitHub
#191 (comment)
.

@dscho
Copy link
Member

dscho commented Aug 17, 2015

@kjeremy so... did you get a chance to address your issue yet?

@kjeremy
Copy link
Author

kjeremy commented Aug 19, 2015

I just copied my .bashrc to .bash_profile.

@dscho
Copy link
Member

dscho commented Aug 19, 2015

I just copied my .bashrc to .bash_profile.

That's a work-around, not a solution, of course. A proper fix would be much more desirable.

@gordontyler
Copy link

The generally accepted solution is to add a line to your .bash_profile which sources .bashrc. Something like this:

[ -f .bashrc ] && source .bashrc

This will ensure that your .bashrc is read for both login shells and interactive, non-login shells.

@dscho
Copy link
Member

dscho commented Aug 19, 2015

@gordontyler That sounds good. Are you sure we do not need to use an explicit $HOME/.bashrc?

I think we need to do this as part of git-extra because there is no /etc/bash.bash_profile yet...

@gordontyler
Copy link

I don't need to use $HOME with msys1/git1. In theory, a login shell is executed with the user's home directory as the current working directory.

I have a /etc/profile but it doesn't source ~/.bash_profile. bash should do that automatically for login shells.

@cristovaov
Copy link

Just a chiming in: @kjeremy starts up the Bash shell with login ( --login) and interactively (-i) just like me (consoleZ ftw!) and like older releases of Git for Win used to launch Bash. And doing so will not load the .bashrc file in the home dir with Bash V4.3 -- See:
http://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html

However the etc/profile file sources the system-wide etc/bash.bashrc file and by simply adding the following conditional at the bottom of this bash.bashrc file, it will restore that old (unnatural?) behavior:
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi

Hope this is helpful! I'd be happy to PR if you can point to where and how ~

@gordontyler
Copy link

However, that page specifically states:

So, typically, your ~/.bash_profile contains the line

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

after (or before) any login-specific initializations.

Perhaps the Git installer should create a $HOME/.bash_profile that does this, if the file doesn't already exist.

@kjeremy
Copy link
Author

kjeremy commented Aug 19, 2015

@dscho How do I find out where bash.bashrc comes from? I've installed the sdk and checked out build-extra but don't see what I should be touching.

@cristovaov
Copy link

While following the manual be the proper way to do it, I think we can forgive the exception for Windows:
Elaborating on my previous comment:

Like @descho suggested adding a home_bashrc.sh (ex. filename) as part of git-extra with the suggested lines (or better) in my previous comment would be more sensible.
I'd rather leave the choice to more knowledgeable users to make use of .bash_profile (by deleting that one git-extra file and not have the installer create any file in the %HOME% dir.

@dscho
Copy link
Member

dscho commented Aug 20, 2015

How do I find out where bash.bashrc comes from?

@kjeremy pacman -Qo /etc/bash.bashrc in the Git SDK.

@cristovaov let's leave @descho out of this, okay? She probably is wondering what us cranky old guys want from her, discussing things that are far, far away from visual design...

@Francisc
Copy link

Is the renaming of .bashrc. to .bash_profile final? As in future releases will always look at .bash_profile and ignore .bashrc?

@nalla
Copy link

nalla commented Aug 20, 2015

@Francisc this is not a rename. See http://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html.

Especially

When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

and

When an interactive shell that is not a login shell is started, Bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force Bash to read and execute commands from file instead of ~/.bashrc.

They just have different "meanings".

@cristovaov
Copy link

@dscho Oh Dear! I apologise I've tagged by mistake :$

@dscho
Copy link
Member

dscho commented Aug 20, 2015

@cristovaov no worries. I would never have seen her photos if it weren't for your tyop. Among others, I like this one a lot.

@Francisc
Copy link

Thanks a lot, @nalla. Awesome reply and everything clear now.

@travi
Copy link

travi commented Aug 20, 2015

I'd like to voice another vote to please keep this consistent with other bash environments and not make this behavior be specific to windows. I know of several people, myself included, that share dotfiles across windows, osx, and linux.

While I agree that the logic determining when .bashrc vs .bash_profile is confusing, now that I've sorted it out I expect it to be predictable. If I provision a new machine and a file is added that causes different behavior, the cause would cost me enough time to track down that I would be pretty frustrated if I didn't have the background of this thread.

If there is confusion around when to use which one, I've always found this superuser answer to be a good sanity check in addition to the link above.

@dscho
Copy link
Member

dscho commented Aug 20, 2015

@travi no worries. There was never a plan to deviate from the behavior in other Bash environments. It is really useful to have a .bash_profile that is only run when logging in, and a .bashrc that is executed whenever a new, non-login bash process is started. That is too useful to give up ;-)

@cristovaov
Copy link

@dscho That is great! It turns out she is an acquaintance of mine - Please do tell her, I think she'd appreciate it :)

@dscho
Copy link
Member

dscho commented Aug 22, 2015

@cristovaov already done...

jeffhostetler added a commit to jeffhostetler/git that referenced this issue Oct 7, 2019
…helper

gvfs-helper: create tool to fetch objects using the GVFS Protocol
jeffhostetler added a commit to jeffhostetler/git that referenced this issue Jun 3, 2020
jeffhostetler added a commit to jeffhostetler/git that referenced this issue May 14, 2021
jeffhostetler added a commit to jeffhostetler/git that referenced this issue Jun 21, 2021
jeffhostetler added a commit to jeffhostetler/git that referenced this issue Aug 18, 2021
mjcheetham pushed a commit to mjcheetham/git that referenced this issue Jun 16, 2022
mjcheetham pushed a commit to mjcheetham/git that referenced this issue Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants