I am wondering if someone out there who is a bash expert can help me with a 
problem with the way that bash startup files are handled.

My problem stems from creating an alias for the ls command in my 
~/.bashrc, but finding that whenever I open an xterm console, that 
alias does not seem to take effect. I know that the profile file is actually 
being executing by placing a line like
        echo "I am here"
into the file, and seeing that "I am here" gets echo'd to any console that I 
open.

I think the problem lies as follows:

My understanding of the way that bash starts up is for a new login session, 
it executes
        ~/.bash_profile
while for a new shell under an existing login session (such as when I fire up 
an xterm) it executes
        /etc/bashrc

Since under the MDK 7.2 install, the supplied ~/.bash_profile executes 
~/.bashrc (if it exists), you can put things that you need for both login 
sessions and new shells under a login session into .bashrc, and things just 
needed when first logging in into .bash_profile.

At the end of .bashrc, it executes 
        /etc/bashrc
which contains "system level" common things that everyone "ought to get" when 
firing up a bash shell. 

/etc/bashrc in turn executes /etc/profile, which eventually finds all files 
of the form /etc/profile.d/*.sh which are executable and runs them. One such 
file is alias.sh, which creates the aliases that MDK thinks you should have 
(for instance, converting rm to rm -i so you will be prompted to confirm all 
file deletes).

This alias.sh contains alias for:
alias l="ls"                    # classique listing.
alias ll="ls -l"                # List detailled.
alias la='ls -A -k'             # List all.
alias lsd="ls -d */"            # List only the directory.

Unforunately, another such file (color_ls.sh) creates an alias for ls, which 
then overrides the alias that I have already created in my ~/.bashrc.

My two questions are thusly:

1. I had thought that bash should run the system wide profiles (eg 
/etc/bashrc) BEFORE the per-user profiles (eg ~/.bash_profile or ~/.bashrc) 
but it seems that it is actually the reverse. Is this correct?

2. The template .bashrc provided in the MDK install places some aliases 
BEFORE the system wide profiles are invoked, which is therefore backwards as 
it would seem that you would want to have your own aliases override system 
provided ones, and not the other way around. Is this correct?

Obviously, for me, the solution is easy - I just move the alias to the end of 
.bashrc, and all works as I need it to. I just want to ensure that I am not 
missing something important here.

Thanks.
Neal

Reply via email to