LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 08-29-2010, 04:18 PM   #1
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Rep: Reputation: 43
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
 
Old 08-29-2010, 04:28 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
What are your .bashrc settings? I assume we are talking about Slackware here, aren't we?
 
Old 08-29-2010, 04:36 PM   #3
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Original Poster
Rep: Reputation: 43
Code:
# .bashrc

# Add bin to path
export PATH="$PATH:/sbin:/usr/sbin:$HOME/bin"

# Add color
eval `dircolors -b`


# User defined aliases

alias ll='ls -la'
alias lsg='ls | grep'
alias llg='ls -la | grep'
Yeah Slackware 13.1
 
Old 08-29-2010, 04:38 PM   #4
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.1
Posts: 2,367

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
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

if [ -e ~/.bashrc ]; then
	. .bashrc
fi
in my ~/.bash_profile

I always launch login shells just to make things easy, but you can probably add
Code:
. /etc/profile
to your .bashrc (before most other things I would imagine, since /etc/profile may override any .bashrc customizations if you source it last) to get everything working as expected in a non-login shell.

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.
 
Old 08-29-2010, 04:48 PM   #5
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Original Poster
Rep: Reputation: 43
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.
 
Old 08-29-2010, 06:11 PM   #6
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,910

Rep: Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026
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:
PS1='\u@\h:\w\$ '

alias ls='ls --color'
And then to make sure that's also run for interactive login shells, call it from a ~/.bash_profile such as:
Code:
case $- in
*i* )  # We're interactive
       if [ -f ~/.bashrc ]; then  # run ~/.bashrc if it exists
          source ~/.bashrc
       fi
       ;;
esac
The case statement ensures that it only gets run for interactive login shells and not non-interactive login shells.


Hope that helps.
 
Old 08-30-2010, 03:49 AM   #7
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Original Poster
Rep: Reputation: 43
Thanks Gazl, that is what I thought, re login & non-login shells.

Quote:
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.
This doesn't happen. Shells open with a blank format, having not sourced my .bash_profile or .bashrc

Last edited by spoovy; 08-30-2010 at 03:57 AM.
 
Old 08-30-2010, 05:29 AM   #8
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,910

Rep: Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026
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.
 
1 members found this post helpful.
Old 08-30-2010, 03:59 PM   #9
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Original Poster
Rep: Reputation: 43
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!
 
Old 08-30-2010, 04:15 PM   #10
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.1
Posts: 2,367

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
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
in your .bashrc will likely clear everything up, as would launching your terminal as a login shell instead of an interactive non-login one. If your .bashrc really isn't being sourced when launching your terminal as an interactive non-login shell then something is wrong...
 
1 members found this post helpful.
Old 08-30-2010, 04:36 PM   #11
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Original Poster
Rep: Reputation: 43
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!
 
Old 08-30-2010, 04:53 PM   #12
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,910

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

Last edited by GazL; 08-30-2010 at 04:55 PM.
 
Old 08-30-2010, 05:49 PM   #13
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Original Poster
Rep: Reputation: 43
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.
 
Old 08-30-2010, 05:51 PM   #14
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.1
Posts: 2,367

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
Quote:
Originally Posted by GazL View Post
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.
I looked through all of /etc/profile and all of /etc/profile.d/*.sh. Most variables are set explicitly from /etc/profile and then added to in /etc/profile.d/*.sh. Unless I am mistaken, there are no side effects (things are reset unnecessarily when they should be inherited but there isn't really a downside) -- with the exception of the following variables:
Code:
XDG_CONFIG_DIRS
PKG_CONFIG_PATH
CPLUS_INCLUDE_PATH
which will have duplicated paths when /etc/profile is sourced from a non-login shell (or when running multiple login shells). It appears as though aliases are not preserved in subsequent shells (and PS1 gets reset by bash itself), so setting the following in .bashrc will allow you to maintain a proper environment without running a login shell:
Code:
alias d='dir'
alias dir='/bin/ls $LS_OPTIONS --format=vertical'
alias ls='/bin/ls $LS_OPTIONS'
alias mc='. /usr/share/mc/bin/mc-wrapper.sh'
alias v='vdir'
alias vdir='/bin/ls $LS_OPTIONS --format=long'
PS1='\u@\h:\w\$ '
export PS1
Untested and keep in mind I am using Slackware 13.0, so any changes between 13.0 and 13.1 are unaccounted for.
 
  


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
hardware profiles bbrahim Linux - Hardware 1 12-02-2008 10:13 AM
Mozilla Profiles Tenover Linux - Newbie 4 09-04-2003 04:29 PM
Help with PDC and Profiles Syntax_Error Linux - Networking 7 02-02-2003 11:10 AM
Netscape profiles jeucken Linux - Software 1 01-09-2003 03:38 PM
Profiles jeucken Linux - Software 2 11-06-2002 08:04 AM

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

All times are GMT -5. The time now is 12:35 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