UbuntuThis forum is for the discussion of Ubuntu Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
in my .bash_profile and /etc/profile a number of paths etc are defined and scripts are sourced. However, under X, ubuntu doesn't seem to read them. Which file do I need to use instead? Will a
source ~/.bash_profile
in .xsession do? If so, why is this implemented this way?
take a look at the FILES section of 'man bash'. each init file has their own purpose. if you're referring to a terminal like xterm or konsole, perhaps only bash_profile and bashrc are read.
Thanks, konsolebox. However, my problem is x login. In other distros the bash init files are read on x login. In ubuntu that does not seem to be the case. My question is: what init files ARE read?
According to the bash info pages, ~/bash_profile should be sourced if the shell is a login shell, unless the --nologin option was used. You could try using "ps -u <your-user-name> | grep bash" to get the PIDs of each bash shell, and look at the command line that was used. For example:
ps -u FogSwimmer | grep bash
9023 pts/1 00:00:00 bash
13336 pts/2 00:00:00 bash
> cat /proc/9023/cmdline
> cat /proc/13336/cmdline
Also, check the /etc/passwd file to make sure that /bin/bash is listed as your default shell.
If not you can use chsh or edit the /etc/passwd file as root to change it.
the problem is, I am not talking about a login shell here but an arbitrary terminal started under an X session, which normally isn't a login shell. Apparently, none of the bash resource files are sourced in that situation under ubuntu. I know they ARE sourced in other distros on Xlogin in any case.
An arbitrary bash shell started after login will source ~/.bashrc. Aliases and paths are normally set when you login however.
For example, a ~/.profile or ~/.bash_profile script will probably contain lines similar to:
if [ -d $HOME/bin ]; then PATH=$PATH:$HOME/bin
If this were in ~/.bashrc, then each time you create a subshell, a duplicate :/home/username/bin entry would be tacked onto the end of the PATH variable.
In post #3 you asked about the shell startup scripts that run during X login. This is when a users initial login shell is started, and thus if you use bash as your default shell, /etc/profile, ~/.bash_login or ~/.profile are sourced. ~/.bashrc is not sourced by bash automatically when logging in, but it is possible that ~/.bash_login or ~/.profile check for its existance and source it. It is also common for a /etc/profile script or a ~/.profile script to also check for the existance of an "aliases" script somewhere.
Also, keep in mind that some commands such as "ls" also check for the existance of variables such as "LC_COLLATE", which could have been inherited from the parent system shell, or may have been created by your system's /etc/profile script or /etc/profile.local script (which is where you would make changes on some systems such as SuSE).
On some distro's, system wide variables are set in scripts contained in /etc/profile.d/. The /etc/profile script maysource any script found in this directory rather than a /etc/profile.local script.
One script may set the terminal colors, another your locale, another your aliases, etc.
The startup scripts run are listed in the info bash manual. For bash and coreutils, I would recommend installing the source and producing the printable manuals in ps or pdf form. If you have the patched source code, this usually entails running "make pdf". As an alternative, running "info:bash" in konqueror is also convenient for the browser based documentation.
Thanks, jschiwal, for your detailed explanations of normal bash startup sourcing. The problem is: this doesn't seem to happen in Ubuntu. /etc/profile for instance is entirely useless. I have a line
source /opt/intel/fc/9.0/bin/ifortvars.sh
in my /etc/profile -- this sets a few variables needed by my fortran compiler. But whenever I open a shell none of those variables are set unless I manually source the above file.
I have quite successfully used the various bash startup scripts in other distros, so I believe this to be a distro-specific problem (hence the choice of forum).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.