0

The problem I had was to get the .bashrc and .bash_profile and/or .profile scripts to execute by default when using the native Gnome terminal application.

I found a number of references which told me in order to get these to "run" you needed to have an interactive session with login but none of the threads I found explained how to do this with the native terminal application.

So my question is how do you get the .bashrc and .bash_profile scripts to run on Centos every time you use the Terminal Application on the Gnome desktop?

closed as unclear what you're asking by Networker, jasonwryan, Ramesh, slm Nov 5 '14 at 1:54

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I have edited my question and trust this clarifies. – bated Nov 5 '14 at 16:29
1

If your terminal starts a normal bash session, that bash will read in ~/.bashrc. If you have additional commands in ~/.bash_profile, those will only be read by the login shell and not by a non-login bash start.

You can easily source ~/.bashrc from ~/.bash_profile with something like:

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

And then move everything else from .bash_profile into ~/.bashrc. Please note that ~/.bash_login is only read by the login shell if ~/.bash_profile is not found, and and ~/.profile are only if ~/.bash_login is not found.

This will work for any terminal program.

  • Hi @Anthon this does not work if you use the native terminal application from the gnome desktop. I tried a number of different variations of this, including .profile and the .bashrc and .bash_profile – bated Nov 4 '14 at 20:59
  • @bated What exactly does not work? Did you put all your bash stuff in .bashrc as I indicated. This works for me and I have about 35 instances of bash open in as many terminal tabs. The only thing that setting "Run command as login shell" does is providing --login to bash, but if ~/.bash_login is almost empty (apart from the 3 lines I gave), the difference is unnoticeable. – Anthon Nov 4 '14 at 21:16
  • The answer you provide is one of the first things I tried. However I could not get ~/.bash_profile to source (tried putting in a simple echo). I deduced that the terminal application must be using a non-login shell which is why this was not firing. – bated Nov 4 '14 at 22:33
0

In the spirit of this I will answer my own question.

So to get this to work:

  1. Open the terminal application in Centos (In the Applications\Accessories\Terminal)
  2. Select the Edit\Current Profile (If you want to make this the default for your current profile)
  3. Select the "Title and Command" tab and tick the option "Run command as login shell"

This then ensures that when you fire up terminal it executes the .profile and .bashrc sourcing.

  • 1
    .bashrc should always be sourced. – muru Nov 4 '14 at 20:52
  • @muru Actually, on a few distributions, this file is never sourced by default. There is no requirement whatsoever when it comes to this, it all depends on what .profile and /etc/profile do. – John WH Smith Nov 4 '14 at 21:04
  • @bated: that's not the answer, that's a hackish workaround. – tink Nov 4 '14 at 21:06
  • @JohnWHSmith Perhaps I should have said ".. in non-login shells", which the terminals open by default. – muru Nov 4 '14 at 21:07
  • 1
    @bated: I understood that perfectly fine. But forcing every open window to become a login shell is not the right way to do this; the question is why your login manager doesn't pull it in, or why your terminal doesn't inherit the values from ~/.bashrc if the login manager did do its job. – tink Nov 4 '14 at 22:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.