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 is running twice when SSH into remote server #537

Closed
cmonty14 opened this issue Feb 29, 2024 · 4 comments
Closed

.bashrc is running twice when SSH into remote server #537

cmonty14 opened this issue Feb 29, 2024 · 4 comments

Comments

@cmonty14
Copy link

Hi,
I deployed ohmybash successfully.
I customized .bashrc in order to start tmux session automatically when SSH into a remote server.

However, .bashrc is executed twice.
I added this code to .bashrc

if [[ $(hostname) != "vlgsplts02" ]] && [[ $(hostname) != "dlm-lts01" ]]; then
  echo "Hello $USER"
fi

and now I get this in CLI:
image

Can you please advise how to fix it?

THX

@akinomyoga
Copy link
Contributor

Sorry for the slow reply. I was busy last week, and I don't have an idea what could cause the behavior in your environment. I need to collect information. What would be the result if you replace echo "Hello $USER" in the above test code as follows?

 if [[ $(hostname) != "vlgsplts02" ]] && [[ $(hostname) != "dlm-lts01" ]]; then
-  echo "Hello $USER"
+  declare -p BASHPID BASH_SOURCE BASH_LINENO >&2
 fi

@cmonty14
Copy link
Author

cmonty14 commented Mar 7, 2024

Thanks for your reply and your support in analyzing this issue.

After modifying .bashrc I get this output:

declare -ir BASHPID="20144"
declare -a BASH_SOURCE=([0]="/sapmnt/HOME/d038783/.bashrc" [1]="/etc/profile")
declare -a BASH_LINENO=([0]="349" [1]="0")
declare -ir BASHPID="20144"
declare -a BASH_SOURCE=([0]="/sapmnt/HOME/d038783/.bashrc" [1]="/sapmnt/HOME/d038783/.bash_profile")
declare -a BASH_LINENO=([0]="5" [1]="0")

Can you conclude from this output why .bashrc is running twice?

@akinomyoga
Copy link
Contributor

Thank you for the information. So ~/.bashrc is sourced from two different places. One place is /etc/profile. The other place is ~/.bash_profile. OMB creates ~/.bash_profile if it doesn't exist because missing ~/.bash_profile causes problems in macOS.

What is your distribution? I'd say /etc/profile sourcing ~/.bashrc is strange. As described in Bash Reference Manual [1] and other places [2,3], ~/.bashrc is supposed to be sourced from ~/.bash_profile. So /etc/profile is not supposed to source ~/.bashrc.

I searched. For example, openSUSE /etc/profile seems to source ~/.bashrc. I have to say the default Bash configurations of openSUSE have been causing problems constantly. It's not maintained well. Maybe the ideal solution is to fix the setup in the distribution, but I'd anticipate that it would be difficult because there are existing users assuming the strange setup of the distributions.

This time, I think you can just comment out the "source ~/.bashrc" part of your ~/.bash_profile.

@cmonty14
Copy link
Author

cmonty14 commented Mar 7, 2024

Actually I'm running SLES, but this should be equal to openSUSE.
However I was using a customized ~/.bashrc before deploying oh-my-bash, and this error was not showing up.

I will now modify ~/.bash_profile and verify if this is working.

Update:
Removing source ~/.bashrc from ~/.bashrc is the solution.

@cmonty14 cmonty14 closed this as completed Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants