`.bashrc` running three times #166

Open
Hypercubed opened this Issue Jun 7, 2014 · 20 comments

Comments

Projects
None yet
9 participants
@Hypercubed

Babun updated this morning to version 1.0.1. Now when starting babun my .bashrc is run three times. It seams now babun is running .profile, .bash_profile and .bashrc. The first two simply invoke the third. Is this desired behavior? This wasn't the case before.

@Hypercubed

This comment has been minimized.

Show comment
Hide comment

My setup is not liking this change:

72420f6#diff-cad3f3ba5f5f8acb51791af96715d7f9R5

@Hypercubed

This comment has been minimized.

Show comment
Hide comment
@Hypercubed

Hypercubed Oct 20, 2014

If nobody else has this issue I'm closing.

If nobody else has this issue I'm closing.

@Hypercubed Hypercubed closed this Oct 20, 2014

@BastiTee

This comment has been minimized.

Show comment
Hide comment
@BastiTee

BastiTee Feb 5, 2015

I also have that issue. Have you done anything to prevent this except for commenting the parts in .profile and .bash_profile?

BastiTee commented Feb 5, 2015

I also have that issue. Have you done anything to prevent this except for commenting the parts in .profile and .bash_profile?

@tombujok

This comment has been minimized.

Show comment
Hide comment
@tombujok

tombujok Mar 31, 2015

Contributor

Fixed in 1.1.0.
Release status: #266

Contributor

tombujok commented Mar 31, 2015

Fixed in 1.1.0.
Release status: #266

@Hypercubed

This comment has been minimized.

Show comment
Hide comment
@Hypercubed

Hypercubed Apr 16, 2015

Can you point me to where this is fixed? Do I need to change my .profile, .bash_profile and .bashrc files to prevent the triple run?

Update: I'm seeing this issue again after updating to 1.1.1

Can you point me to where this is fixed? Do I need to change my .profile, .bash_profile and .bashrc files to prevent the triple run?

Update: I'm seeing this issue again after updating to 1.1.1

@Hypercubed Hypercubed reopened this Apr 16, 2015

@Hypercubed

This comment has been minimized.

Show comment
Hide comment
@Hypercubed

Hypercubed Apr 16, 2015

More information:

The default cygwin ~/.profile invokes "${HOME}/.bashrc"
The default cygwin ~/.bash_profile sources "${HOME}/.bashrc"
babun-core/plugins/core/src/babun.bash sources "$homedir/.profile" and "$homedir/.bash_profile".

Somewhere else "~/.bashrc" is sourced as well because it is run three times. I don't know why babun.bash needs to source anything at all, and apperently it did not before this change: 72420f6#diff-cad3f3ba5f5f8acb51791af96715d7f9R5

More information:

The default cygwin ~/.profile invokes "${HOME}/.bashrc"
The default cygwin ~/.bash_profile sources "${HOME}/.bashrc"
babun-core/plugins/core/src/babun.bash sources "$homedir/.profile" and "$homedir/.bash_profile".

Somewhere else "~/.bashrc" is sourced as well because it is run three times. I don't know why babun.bash needs to source anything at all, and apperently it did not before this change: 72420f6#diff-cad3f3ba5f5f8acb51791af96715d7f9R5

@tkossak

This comment has been minimized.

Show comment
Hide comment
@tkossak

tkossak Aug 22, 2015

Thanks for solution. I have babun 1.2.0 and the same problem.

tkossak commented Aug 22, 2015

Thanks for solution. I have babun 1.2.0 and the same problem.

@tombujok

This comment has been minimized.

Show comment
Hide comment
@tombujok

tombujok Aug 23, 2015

Contributor

@Hypercubed Could you try to pinpoint the bug and submit a PR?

Contributor

tombujok commented Aug 23, 2015

@Hypercubed Could you try to pinpoint the bug and submit a PR?

@Hypercubed

This comment has been minimized.

Show comment
Hide comment
@Hypercubed

Hypercubed Aug 25, 2015

I could but I am not sure where the fix should be. If you look here: https://github.com/babun/babun/blob/master/babun-core/plugins/core/src/babun.bash#L5 both "$homedir/.profile" and "$homedir/.bash_profile" are being sourced. But often these files do something like this:

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

So, is it a user error that .profile and .bash_profile are identical?

/etc/skel/.profile contains:

# This file is not read by bash(1) if ~/.bash_profile or ~/.bash_login
# exists.
#
# if running bash
if [ -n "${BASH_VERSION}" ]; then
  if [ -f "${HOME}/.bashrc" ]; then
    source "${HOME}/.bashrc"
  fi
fi

So is that the correct behavior for babun.bash?

I could but I am not sure where the fix should be. If you look here: https://github.com/babun/babun/blob/master/babun-core/plugins/core/src/babun.bash#L5 both "$homedir/.profile" and "$homedir/.bash_profile" are being sourced. But often these files do something like this:

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

So, is it a user error that .profile and .bash_profile are identical?

/etc/skel/.profile contains:

# This file is not read by bash(1) if ~/.bash_profile or ~/.bash_login
# exists.
#
# if running bash
if [ -n "${BASH_VERSION}" ]; then
  if [ -f "${HOME}/.bashrc" ]; then
    source "${HOME}/.bashrc"
  fi
fi

So is that the correct behavior for babun.bash?

@Hypercubed

This comment has been minimized.

Show comment
Hide comment
@Hypercubed

Hypercubed Aug 25, 2015

BTW, I bypassed this issue in my setup with this line:

[[ -z ${USER_BASHRC} ]] && USER_BASHRC="1" || return

Which is probably good practice anyway.

BTW, I bypassed this issue in my setup with this line:

[[ -z ${USER_BASHRC} ]] && USER_BASHRC="1" || return

Which is probably good practice anyway.

@tkossak

This comment has been minimized.

Show comment
Hide comment
@tkossak

tkossak Aug 25, 2015

BTW, I bypassed this issue in my setup with this line:

[[ -z ${USER_BASHRC} ]] && USER_BASHRC="1" || return
Which is probably good practice anyway.

it would have a side effect of disabling source ~/.bashrc which i like doing after changing it

tkossak commented Aug 25, 2015

BTW, I bypassed this issue in my setup with this line:

[[ -z ${USER_BASHRC} ]] && USER_BASHRC="1" || return
Which is probably good practice anyway.

it would have a side effect of disabling source ~/.bashrc which i like doing after changing it

@Hypercubed

This comment has been minimized.

Show comment
Hide comment
@Hypercubed

Hypercubed Aug 25, 2015

@tkossak You are correct. With that work aroudn I cannot re-source ~/.bashrc

According to this "[bash] reads from the first of .bash_profile, .bash_login and .profile (only)". If I remove the two lines from \usr\local\etc\babun.bash bash starts as expected. These two lines were added deliberately by @tombujok over a year ago (72420f6#diff-cad3f3ba5f5f8acb51791af96715d7f9R5).

@tkossak You are correct. With that work aroudn I cannot re-source ~/.bashrc

According to this "[bash] reads from the first of .bash_profile, .bash_login and .profile (only)". If I remove the two lines from \usr\local\etc\babun.bash bash starts as expected. These two lines were added deliberately by @tombujok over a year ago (72420f6#diff-cad3f3ba5f5f8acb51791af96715d7f9R5).

@tkossak

This comment has been minimized.

Show comment
Hide comment
@tkossak

tkossak Aug 25, 2015

If this file \usr\local\etc\babun.bash is responsible for double bashrc startup (I don't know), then yes the lines:

+test -f "$homedir/.profile" && source "$homedir/.profile"
+test -f "$homedir/.bash_profile" && source "$homedir/.bash_profile"

should be changed into something like:

if   [[ -r "$homedir/.bash_profile" ]]; then
    source "$homedir/.bash_profile"
elif [[ -r "$homedir/.bash_login" ]]; then
    source "$homedir/.bash_login"
elif [[ -r "$homedir/.profile" ]]; then
    source "$homedir/.profile"
fi

According to Bash Manual this is the exact sequence for interactive shells (after executing /etc/profile of course). And yes - it should only start one file from these 3 - the first one it finds.

tkossak commented Aug 25, 2015

If this file \usr\local\etc\babun.bash is responsible for double bashrc startup (I don't know), then yes the lines:

+test -f "$homedir/.profile" && source "$homedir/.profile"
+test -f "$homedir/.bash_profile" && source "$homedir/.bash_profile"

should be changed into something like:

if   [[ -r "$homedir/.bash_profile" ]]; then
    source "$homedir/.bash_profile"
elif [[ -r "$homedir/.bash_login" ]]; then
    source "$homedir/.bash_login"
elif [[ -r "$homedir/.profile" ]]; then
    source "$homedir/.profile"
fi

According to Bash Manual this is the exact sequence for interactive shells (after executing /etc/profile of course). And yes - it should only start one file from these 3 - the first one it finds.

@Hypercubed

This comment has been minimized.

Show comment
Hide comment
@Hypercubed

Hypercubed Aug 26, 2015

As far as I can tell the lines are not needed. Bash is responsible for loading .bash_profile etc. @tombujok needs to help us understand why the change was made... if he can recall.

As far as I can tell the lines are not needed. Bash is responsible for loading .bash_profile etc. @tombujok needs to help us understand why the change was made... if he can recall.

@Hypercubed

This comment has been minimized.

Show comment
Hide comment
@Hypercubed

Hypercubed Sep 6, 2015

I got bit by this again. The solution, I think, is to simply remove the two test -f lines from /usr/local/etc/babun.bash

I got bit by this again. The solution, I think, is to simply remove the two test -f lines from /usr/local/etc/babun.bash

@qwertzguy

This comment has been minimized.

Show comment
Hide comment
@qwertzguy

qwertzguy Apr 22, 2016

Removing the two test -f lines like @Hypercubed mentioned, worked for me as well.

Removing the two test -f lines like @Hypercubed mentioned, worked for me as well.

@chrisjbreisch

This comment has been minimized.

Show comment
Hide comment
@chrisjbreisch

chrisjbreisch Sep 22, 2016

Note that this behavior is incorrect. The bash manpage says that if ~/.bash_profile exists, then ~/.profile should not be run. Also, if /usr/local/etc/babun.bash is going to set PS1, it should do it before sourcing the user's .bash_profile, as PS1 might be set there, and now you're overriding user customization.

Note that this behavior is incorrect. The bash manpage says that if ~/.bash_profile exists, then ~/.profile should not be run. Also, if /usr/local/etc/babun.bash is going to set PS1, it should do it before sourcing the user's .bash_profile, as PS1 might be set there, and now you're overriding user customization.

@grant-humphries

This comment has been minimized.

Show comment
Hide comment
@grant-humphries

grant-humphries Dec 20, 2016

An issue I've experienced with the current setup of babun.bash in additon what is discussed above is that it sources /etc/profilein all cases, even though, by bash convention, that file is supposed to be run only when bash is launched as a login shell. If you do run bash as a login shell (which is what babun.bat does) /etc/profile is loaded twice which is problematic for me because this nullifies the CHERE_INVOKING environment variable which prevents /etc/profile from cd'ing in to the home directory. Not launching bash as login shell can be a work around but then the setting shopt login_shell is set to off which has other ramifications.

It seems to me that babun should not be sourcing any profile-type files (/etc/profile, .bash_profile, .profile, .bashrc, etc.) as bash already handles this in an established manner and reloading those files causes unexpected behavior and a longer loading time when the shell is launched.

grant-humphries commented Dec 20, 2016

An issue I've experienced with the current setup of babun.bash in additon what is discussed above is that it sources /etc/profilein all cases, even though, by bash convention, that file is supposed to be run only when bash is launched as a login shell. If you do run bash as a login shell (which is what babun.bat does) /etc/profile is loaded twice which is problematic for me because this nullifies the CHERE_INVOKING environment variable which prevents /etc/profile from cd'ing in to the home directory. Not launching bash as login shell can be a work around but then the setting shopt login_shell is set to off which has other ramifications.

It seems to me that babun should not be sourcing any profile-type files (/etc/profile, .bash_profile, .profile, .bashrc, etc.) as bash already handles this in an established manner and reloading those files causes unexpected behavior and a longer loading time when the shell is launched.

kenjones-cisco added a commit to kenjones-cisco/babun that referenced this issue Apr 20, 2017

@ehaynes99

This comment has been minimized.

Show comment
Hide comment
@ehaynes99

ehaynes99 Jun 20, 2017

Can this be merged? As stated in the file, it will be overwritten on update and should not be modified directly.

Can this be merged? As stated in the file, it will be overwritten on update and should not be modified directly.

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