View previous topic :: View next topic |
Author |
Message |
i92guboj Bodhisattva
Joined: 30 Nov 2004 Posts: 10315 Location: Córdoba (Spain)
|
Posted: Wed May 11, 2005 5:37 pm Post subject: [bash] - What I know about config files - (Lil howto) |
|
|
Hi all.
I was a bit bored this evening and decided to take a look to the configuration files for bash. It seemed a bit obscured to me in Gentoo so I've put that here is hope that it will be usefull for someone.
As stated in the bash manpage (a great man, btw) there are many ways to start bash (you can call it 'modes'). From these I'm only interested in the two interactive ones, that are the two that are responsible for so much convesations about "Where do I put this for it to start with my bash?".
1.- Interactive-Login bash
First one is the login-interactive shell mode. For example when we start the system in console mode or when you explictly call bash with '--login' parameter. Then the first file sourced is /etc/profile, and (if existent and reachable) then one of:
~/.bash_profile
~/.bash_login
~/.profile
Is also sourced. Only one of them is ran, and they are checked in that order. I created that three file and put a little 'echo This is from <filename>' by the end of each file, this is what I get when logging in from console:
Code: |
This is from /etc/profile
This is from /home/6thpink/.bash_profile
|
If I remove the ~/.bash_profile then I get:
Code: |
This is from /etc/profile
This is from /home/6thpink/.bash_login
|
As expected.
When we log out then ~/.bash_logout is sourced if found and readable. But, and this is not documented in the bash man page, also /etc/bash/bash_logout is sourced, regarless if the ~/.bash_logout is sourced or not. I've put a little 'echo This is from <filename>' by the end of each file, this is what I get when logging out:
Code: |
This is from /home/6thpink/.bash_logout
This is from /etc/bash/bash_logout
|
2.- Interactive (but not login) bash.
In the man page is specified that when starting in non login but interactive bash the only file sourced is ~/.bashrc.
In Gentoo at least, another one more file is sourced, regardless that the standard ~/.bashrc is or not found. That file is /etc/bash/bashrc. Again, we find here a non documented feature that makes also the /etc/bash/bashrc to be sourced when we start bash as a non-login shell. And again, regardless the ~/.bashrc has been found and sourced or not.
Code: |
This is from /etc/bash/bashrc
This is from /home/6thpink/.bashrc
|
As you can see the ~/.basrhc is ran after, so there is no problem in the other one overwriting our config, but that can make the inicialization of bash a bit longer.
I don't know if this features have been documented somewhere else. I also can't say if the reason of this is that the man page is a bit out to date or this is just any feature that is introduced only in Gentoo. So if someone do know anything about this I would be pleased if s/he let me know about.
EDIT: DT&T is not a place for discussion. --pjp
6thpink's EDIT: I'm scared, no irony intended, but, really: do you think that bash configuration files can't fit into tip & tricks? Did you read the p0st before moving it or did you read just the tittle? I don't intend to evaluate moderator's work, just to point out that I think that this would be more helpfull in tip & tricks. Anyway, I modified the tittle. |
|
Back to top |
|
|
swimmer Veteran
Joined: 15 Jul 2002 Posts: 1330 Location: Netherlands
|
Posted: Thu Mar 08, 2007 10:44 am Post subject: |
|
|
Thanx for the nice summary and the work you put into it
Greetz
swimmer |
|
Back to top |
|
|
The Unknown Guru
Joined: 28 Feb 2007 Posts: 335 Location: Minnesota, U.S.A
|
Posted: Thu Mar 08, 2007 11:16 pm Post subject: |
|
|
@6thpink
It is coincidence that you bring this up.I am studying Linux through a book written by Mark G. Sobell and I happen to be on the bash chapter.
His reference to this is /etc/bashrc, I am making a bold assumption that is the same as /etc/bash/bashrc.
He says and I quote "although not called by bash directly,many ~/.bashrc files call /etc/bashrc.This setup allows Superuser to establish systemwide
default characteristics for nonlogin bash shells.
I too would love more clarification if possible for my studies. |
|
Back to top |
|
|
jonnevers Veteran
Joined: 02 Jan 2003 Posts: 1594 Location: Gentoo64 land
|
Posted: Thu Mar 08, 2007 11:21 pm Post subject: |
|
|
here is what I do to cut down on the infuriating way .bash* files are sourced during the various login methods:
put all the stuff i want to happen in ~/.bash_profile
such as:
Code: | export http_proxy="www-proxy.somedomain.com:8080"
export RSYNC_PROXY="www-proxy.somedomain.com:8080"
export ftp_proxy="www-proxy.somedomain.com:8080" |
then put this in ~/.bashrc
Code: | if [ -e ~/.bash_profile ] ; then
. ~/.bash_profile
fi |
this seems to work, except that it dosen't seem to affect my gnome desktop session automatically (I had to set my proxies through gnome's control panel). |
|
Back to top |
|
|
i92guboj Bodhisattva
Joined: 30 Nov 2004 Posts: 10315 Location: Córdoba (Spain)
|
Posted: Thu Mar 08, 2007 11:50 pm Post subject: |
|
|
The Unknown wrote: | @6thpink
It is coincidence that you bring this up.I am studying Linux through a book written by Mark G. Sobell and I happen to be on the bash chapter.
His reference to this is /etc/bashrc, I am making a bold assumption that is the same as /etc/bash/bashrc.
He says and I quote "although not called by bash directly,many ~/.bashrc files call /etc/bashrc.This setup allows Superuser to establish systemwide
default characteristics for nonlogin bash shells.
I too would love more clarification if possible for my studies. |
If you look at the original date, this post is almost two years old hehehe, it is that someone bumped it now It remains equally valid, though
And yes, that is a tipical thing to set on ~./bashrc, but I would not rely on it. Each user has the power to bypass that by editing his/her bashrc file, so, if you really want a global setting you need to use /etc/profile for interactive-login sessions, and /etc/bash/bashrc for interactive-non-login sessions. |
|
Back to top |
|
|
jonnevers Veteran
Joined: 02 Jan 2003 Posts: 1594 Location: Gentoo64 land
|
Posted: Fri Mar 09, 2007 12:26 am Post subject: |
|
|
6thpink wrote: | so, if you really want a global setting you need to use /etc/profile for interactive-login sessions, and /etc/bash/bashrc for interactive-non-login sessions. |
yeah good point. |
|
Back to top |
|
|
The Unknown Guru
Joined: 28 Feb 2007 Posts: 335 Location: Minnesota, U.S.A
|
Posted: Fri Mar 09, 2007 12:30 am Post subject: |
|
|
I feel stupid
But I appreciate your knowledge. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|