Shell profiles?
When I open a terminator I get this prompt: bash-4.1$
which does not include my .bashrc settings. If I then do a "su - spoovy" my prompt turns to: spoovy@darkstar: which is fine. When I do a "su -" to change to root shell, I tend to Ctrl+D to go back to my user shell. Only it doesn't, it goes back to my "bash-4.1$" shell. I don't know what's going on here i'm afraid. Why isn't my .bashrc read when i open a terminal? And why does it drop back to this 'blank format' shell all the time? Thanks spoov |
What are your .bashrc settings? I assume we are talking about Slackware here, aren't we?
|
Code:
# .bashrc |
I am (possibly incorrectly) assuming this is an artifact of starting a non-login shell instead of a login one. See `man bash` and search for INVOCATION. .bashrc is only read when a non-login shell is opened. ~/.bash_profile (and /etc/profile) are only read when a login shell is started. The default user@host:directory$ PS1 variable is exported in /etc/profile, which is only read when starting a login shell. Note that starting a login shell will NOT automatically read .bashrc as well -- and hence I have
Code:
#!/bin/sh I always launch login shells just to make things easy, but you can probably add Code:
. /etc/profile You must think of your usage scenarios and how you differentiate between login and non-login shells when constructing your .bashrc and .bash_profile files. If you don't differentiate at all, then you're safe sourcing the other file; if you do though, it may require a more complex setup. |
Err.. I think this requires some more reading!
I actually thought it was the other way round, that "su -" started a login shell, which in my case does source my .bashrc, whereas "su" starts a nonlogin shell. I need to swot up on all this, I remember being confused by it all when I last looked into it a long time ago. I do already have a .bash_profile with those same lines in by the way. |
su - user (a.k.a su -l user) does start a login shell. Login shells run /etc/profile, followed by the ~/.bash_profile or ~/.bash_login or ~/.profile
su user runs a non-login shell which (assuming it's bash) will run ~/.bashrc. When you start a terminal or xterm, it will normally run a non-login shell and that should run .bashrc but not the profile files. Also be aware that su in slackware 13.1 is broken and that may cause problems under certain circumstances. I've patched it here locally to get it working properly and reported the problem to Pat a while ago, but I'm sad to say that he's not done anything about it yet in either current or stable. :( Anything you want to be available to all interactive bash shells, such as your aliases and PS= string: put in your ~/.bashrc Code:
Code:
case $- in Hope that helps. |
Thanks Gazl, that is what I thought, re login & non-login shells.
Quote:
|
By 'blank format' do you mean the "bash-4.1" prompt? If so then I notice that you don't actually set PS= in your .bashrc above.
Sometimes it helps when trying to debug these things to put a echo "running .bashrc" in your bashrc script, and a similar one saying bash_profile in your .bash_profile. That way you can clearly see what's going wrong and at what stage. |
You know, I don't have PS variable set in either :-P . But its deffo not sourcing my .bashrc as the color aliases don't work in my "blank format" shell.
So where is it getting "spoovy@darkstar:" from when I start a login shell anyway?? I did as you suggest re the echo commands. When I "su - spoovy" from within a shell I get both .bash_profile and .bashrc sourced. When I open a new, fresh terminal, neither is sourced, hence the "blank format" of "bash-4.1". I'm totally baffled by this now! |
When everything is working, it is a login shell that has sourced /etc/profile, which in turn sources the *.sh scripts in /etc/profile.d/, including /etc/profile.d/coreutils-dircolors.sh, which properly sets colours. PS1 is set in /etc/profile itself. In /etc/profile.d/coreutils-dircolors.sh, it sets LS_OPTIONS to "--color=auto" by default. Though you are running `dircolors -b` in your .bashrc, ls is still defaulting to --color=false I believe (though this is a guess). As I said before, putting
Code:
. /etc/profile |
Sorry T3 I must've missed that in your previous post d'oh! I did insert that though, and it did indeed work.
I will go through all these posts again and really work this out some other time, it's too late now. But thanks for your help guys! |
Time to go back to basics I think.
Please define what you mean when you say 'new fresh terminal'. xterm? konsole? xfce-terminal? What happens if you just type 'bash' at the command line? does it run your .bashrc then? Perhaps you can talk us through it step by step so we understand exactly what it is you're doing. I respectfully disagree with T3Sliders advice. the profile files are intended to contain things that run only once in a session, it's not meant to be run for every new shell, so sourcing it from .bashrc is exactly the opposite of what it's intended for. Slackware itself puts things in /etc/profile and by extension /etc/profile.d that really don't belong in there (the aliases and PS prompts being a prime example), so I can understand why T3 is suggesting you do that, but it's a case of attempting to use two wrongs to make a right. Besides, if you say it's not running you .bashrc at all, then sourcing /etc/profile from it really isn't going to help. edit: Ahh I see you've done what T3 suggested and it's now working, so clearly it was sourcing your .bashrc after all. |
To clarify things then, for your information if you want it..
*Previous to adding ". /etc/profile" to my .bashrc - * I would open a terminator using dmenu. It would open with the "bash-4.1" prompt, and with no color in the ls commands. So, in order to get my colors and recognisable prompt I had to type "su - spoovy" and enter my password, in order to open a new login shell. This would then have "spoovy@darkstar" in the prompt, and my colors would be there. If I needed to become root, I would "su -" which would then give me "root@darkstar" prompt, and a normal root shell. If I then pressed Ctrl+D it would print "logout" and return me to "spoovy@darkstar". If I pressed Ctrl+D again, it would print "exit" and return me to the "bash-4.1" prompt, and no colors. *Since adding ". /etc/profile" to my .bashrc, and the 'troubleshooting' echo commands, - * Now, when I open a new shell, it does print "sourcing .bashrc", and give me the "spoovy@darkstar" prompt, and colors. When I type "bash" in that same shell, it echos the same "sourcing .bashrc" and returns the same prompt. So it appears to me that there were two things that were throwing me. A new terminator shell was sourcing my .bashrc all along, but not the color element, as T3Slider described. It also wasn't showing my username in the prompt as I hadn't set PS variable in my .bashrc (an oversight on my part). Phew. |
Quote:
Code:
XDG_CONFIG_DIRS Code:
alias d='dir' |
All times are GMT -5. The time now is 06:19 PM. |