LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 09-26-2006, 02:20 AM   #1
FogSwimmer
Member
 
Registered: Sep 2003
Distribution: Kubuntu / debian / SuSE
Posts: 73

Rep: Reputation: 15
.bash_profile and /etc/profile not sourced?


Hi all,

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?

All best,
f
 
Old 09-26-2006, 02:39 AM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
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.
 
Old 09-28-2006, 03:40 AM   #3
FogSwimmer
Member
 
Registered: Sep 2003
Distribution: Kubuntu / debian / SuSE
Posts: 73

Original Poster
Rep: Reputation: 15
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?

All best,
fogswimmer
 
Old 09-28-2006, 03:49 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
do you have a file /etc/bash.bashrc?

edit: try '# find /etc | grep bash -i' to find an init file.

best luck.

Last edited by konsolebox; 09-28-2006 at 03:52 AM.
 
Old 09-28-2006, 05:12 AM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.

Last edited by jschiwal; 09-28-2006 at 05:14 AM.
 
Old 09-29-2006, 01:28 AM   #6
FogSwimmer
Member
 
Registered: Sep 2003
Distribution: Kubuntu / debian / SuSE
Posts: 73

Original Poster
Rep: Reputation: 15
Thanks konsolebox and jschiwal,

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.

All best
fogswimmer
 
Old 09-30-2006, 08:46 AM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.

Last edited by jschiwal; 09-30-2006 at 08:56 AM.
 
Old 10-05-2006, 05:45 AM   #8
FogSwimmer
Member
 
Registered: Sep 2003
Distribution: Kubuntu / debian / SuSE
Posts: 73

Original Poster
Rep: Reputation: 15
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).

All best,
f
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/etc/profile VERSUS /home/.bash_profile carbono Linux - Newbie 12 10-12-2005 09:23 AM
.bashrc not being sourced shanenin Linux - Software 1 01-05-2005 10:07 PM
.bashrc not sourced koyi Slackware 4 08-02-2003 10:00 AM
.profile & .bash_profile on $LFS cbates55 Linux - Distributions 1 01-02-2002 02:25 PM
profile, .bash_profile & ???? ChimpFace9000 Linux - General 1 07-05-2001 04:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 10:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration