[SOLVED] Slackware 13.0 ~/.bash_profile not running at login
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
When I log in or start a new shell (terminal/xterm) in X, I expected to see the echo and directory at the shell prompt. But it doesn't.
However, if I explicitly 'source' the .bash_profile it works.
What am I doing wrong?
Thanks,
Ash.
Click here to see the post LQ members have rated as the most helpful post in this thread.
Ok, here's what the bash man pages have to say on the subject:
Code:
INVOCATION
A login shell is one whose first character of argument zero is a -, or
one started with the --login option.
An interactive shell is one started without non-option arguments and
without the -c option whose standard input and error are both connected
to terminals (as determined by isatty(3)), or one started with the -i
option. PS1 is set and $- includes i if bash is interactive, allowing
a shell script or a startup file to test this state.
The following paragraphs describe how bash executes its startup files.
If any of the files exist but cannot be read, bash reports an error.
Tildes are expanded in file names as described below under Tilde Expan‐
sion in the EXPANSION section.
When bash is invoked as an interactive login shell, or as a non-inter‐
active shell with the --login option, it first reads and executes com‐
mands from the file /etc/profile, if that file exists. After reading
that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the first one that
exists and is readable. The --noprofile option may be used when the
shell is started to inhibit this behavior.
When a login shell exits, bash reads and executes commands from the
file ~/.bash_logout, if it exists.
When an interactive shell that is not a login shell is started, bash
reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if
these files exist. This may be inhibited by using the --norc option.
The --rcfile file option will force bash to read and execute commands
from file instead of /etc/bash.bashrc and ~/.bashrc.
Opening a new terminal in X invokes bash as an interactive shell, but not as a login shell. Therefore your ~/.bash_profile will not execute, but your ~/.bashrc should.
It sounds to me like bash is not your default shell.
The other question that might be worth asking is what window manager you're using... back when I used slackware, I used fvwm, which had a text based config file. If the shell is launched from one of the menus, it's possible that it's invoking either bash or some other shell in a strange way, based on the config file... that's a streach, I know, but worth a shot.
But I don't quite understand what was going on before.
From what I could tell, it looked like I was in bash.
I am using Xfce for the window manager. I also switched to kde but that didn't make any difference.
The following is some information before I fixed it.
But I thought the default in Slackware was bash if it wasn't specified.
What seems a little odd though was the value of my $PS1.
From the man pages
Quote:
...it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile ...
Code:
/etc/profile
# Set a default shell prompt:
#PS1='`hostname`:`pwd`# '
if [ "$SHELL" = "/bin/pdksh" ]; then
PS1='! $ '
elif [ "$SHELL" = "/bin/ksh" ]; then
PS1='! ${PWD/#$HOME/~}$ '
elif [ "$SHELL" = "/bin/zsh" ]; then
PS1='%n@%m:%~%# '
elif [ "$SHELL" = "/bin/ash" ]; then
PS1='$ '
else
PS1='\u@\h:\w\$ '
fi
So even if my ~/.bash_profile and ~/.bashrc was not being read for whatever reason, I would have expected $PS1=\u@\h:\w\$ . But it was different. Where could that have been coming from?
Code:
sh-3.1$ echo $PS1
\s-\v\$
Thanks,
Ash.
Last edited by ash_zz_00; 01-30-2010 at 03:15 PM.
Reason: Fixed typo in code section
The "problem" is that, once you're logged in (into X, in this case)
all subsequently invoked shells aren't login shells, so all
that gets invoked for them is ~/.bashrc.
Oh, sorry... you need to put your actual username where it says <username>. You don't actually need to pipe it through cut, that just shows you the correct field in the password file.
Quote:
Originally Posted by ash_zz_00
But I thought the default in Slackware was bash if it wasn't specified.
What seems a little odd though was the value of my $PS1.
From the man pages
Quote:
...it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile ...
Code:
/etc/profile
# Set a default shell prompt:
#PS1='`hostname`:`pwd`# '
if [ "$SHELL" = "/bin/pdksh" ]; then
PS1='! $ '
elif [ "$SHELL" = "/bin/ksh" ]; then
PS1='! ${PWD/#$HOME/~}$ '
elif [ "$SHELL" = "/bin/zsh" ]; then
PS1='%n@%m:%~%# '
elif [ "$SHELL" = "/bin/ash" ]; then
PS1='$ '
else
PS1='\u@\h:\w\$ '
fi
So even if my ~/.bash_profile and ~/.bashrc was not being read for whatever reason, I would have expected $PS1=\u@\h:\w\$ . But it was different. Where could that have been coming from?
Code:
sh-3.1$ echo $PS1
\s-\v\$
Thanks,
Ash.
If you go upwards in the man pages a scoche, you'll find that this section refers only to login shells. Essentially, this means that if you have to put your username and password in in order to access the shell its self, you'll be executing /etc/profile, ~/.bash_profile, ~/.bash_login, etc... however, you're launching from within X. If you're running X, you're not running a login shell. Either you've logged in to X, via xdm, or logged in to another shell, then launched X via startx or xsession or something like that. As such from X, you're launching an interactive shell, but not a login shell. An interactive bash shell which is not a login shell will call ~/.bashrc.
Oh, sorry... you need to put your actual username where it says <username>. You don't actually need to pipe it through cut, that just shows you the correct field in the password file.
I did put in my username and I checked the passwd file too. That field was empty.
So it made me wonder how I created the user account. To test it, I ran the "adduser" command. After a number of prompts, it asked for the shell (with /bin/bash as the default). When I grep'd the passwd file, it had the /bin/bash entry.
What could I have done because mine didn't have it? Then I realized that I might have run "useradd" instead. So I tested with it. Indeed, the shell entry is blank.
Quote:
If you go upwards in the man pages a scoche, you'll find that this section refers only to login shells.
Actually I had the same problem with the shell as soon as I logged on (which would be the login shell right?). I don't use xdm/kdm to log in.
Quote:
As such from X, you're launching an interactive shell, but not a login shell. An interactive bash shell which is not a login shell will call ~/.bashrc.
So if I don't have a ~/.bashrc or for some reason my .bashrc is not being invoked, do you know where the interactive shell gets its defaults?
Again, thanks for you help. I'm asking all these questions just to understand better.
Regards,
Ash.
PS: By the way how do I get the "Originally Posted by ..." into the quote. Is that a manual copy/paste?
I did put in my username and I checked the passwd file too. That field was empty.
That would explain why .bashrc never ran. I'm not 100% sure what happens when the shell field is not set, but my guess is that /bin/sh gets called.
/bin/sh is typically a symbolic link to another shell. Which shell gets called varies from distro to distro. Usually this will either be ash or bash, although Debian uses a shell called dash. Here's the kicker: if called as /bin/sh, each of these shells will be called as a POSIX shell, meaning that they only execute the POSIX subset of shell commands. This is important for portability concerns. Among other things, this means that even if the symlink for /bin/sh points to /bin/bash, .bashrc won't be called for a non-login interactive shell, and .bash_profile won't be called for login shells.
.profile is the old standard that bash uses for setting its environment variables. So create one (.profile) if it does not exist in your home directory. As bartonski has mentioned, /bin/sh does not call .bash_profile. So you will have to manually call .bash_profile inside .profile
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.