LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   alias command - verify where it gets info from (https://www.linuxquestions.org/questions/linux-newbie-8/alias-command-verify-where-it-gets-info-from-916206/)

loadedmind 11-29-2011 10:32 AM

alias command - verify where it gets info from
 
Hey all. Ok, so here's the background:

I setup a shell account on an internet service provider and noticed it has a default set of aliases. I use ls -la to verify which dot files are in my home directory and then cat them out to see which contains the aliases. The issue is that none of these files contains those aliases. So, I create another dot file called .bash_profile and place an alias in there, then type bash to test the alias - no dice. So, apparently, another file somewhere contains these aliases and will not permit me to use my own without using the temporary solution (alias command='new command'). So, I thought, perhaps strace can tell me what alias is doing to determine where it pulls the info it's using. Doesn't work that way, apparently.

Can anyone please tell me how to determine what alias is doing, either through env/set's output or otherwise?

Tinkster 11-29-2011 11:09 AM

How about you show us what the dot-files in your home look like?
Chances are the aliases you see are being sourced from a file
~/.bash_login (or ~/.bash_profile or ~/.profile or ~/.bashrc)
pull in from etc ...


Cheers,
Tink

loadedmind 11-30-2011 02:50 PM

I meant to include that the first go around - my bad.

Here tiz:

----Begin Paste----
ls -la
total 16
drwx------ 2 dwood Mailbox 4096 Nov 30 14:48 .
drwx--x--x 6 dwood Mailbox 4096 Nov 29 09:19 ..
dwood@fly:35:~/work$
----End Paste----

Typically, I would see dot files and, if not, I can create a .bash_profile to put my aliases in, but not the case. Here's some more interesting information:

----Begin Paste----
dwood@fly:35:~/work$ alias
alias ls='ls --color=tty'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
----End Paste----

The results of the alias command mean that something somewhere is obviously tied to this account. Regardless of whether I create the .bash_profile and place my own aliases in it or not, that last command is always the same. This is why it would be so great to have something tell me where this information is being gleaned from.

Tinkster 11-30-2011 03:17 PM

Code:

find /etc -type f -exec grep -H "alias" {} \;

rknichols 12-01-2011 10:30 AM

Quote:

Originally Posted by loadedmind (Post 4538517)
Regardless of whether I create the .bash_profile and place my own aliases in it or not, that last command is always the same.

Note that bash reads ~/.bash_profile only when it is a login shell. When invoked as a non-login shell it reads ~/.bashrc .

loadedmind 01-05-2012 10:15 AM

Tinkster - thank you for your reply. I ran the command you provided and there were a lot of results - pages and pages in fact. Not sure what info you'd like to see from that output. I can tell you that I've checked /etc/bashrc and the .bashrc file in my home directory and neither contain the output I receive when typing the "alias" command.

rknichols - thank you for your reply. Understood regarding what gets read. I've checked all of those files for the alias output and none of them contain those entries. This is what's mistifying.

rknichols 01-05-2012 10:34 AM

It is common for /etc/bashrc to source all of the .sh files in /etc/profile.d . Have you checked there?

loadedmind 01-05-2012 10:44 AM

Thanks! I found colorls.sh in the /etc/profile.d directory, but the question remains - how do I trump what's being addressed in /etc/profile.d when I want to create my own aliases? Or should I simply remove the .sh files within /etc/profile.d to prevent them from being confused with my entries in ~/.bash_profile?

rknichols 01-05-2012 01:21 PM

You will probably find that your own .bashrc sources /etc/bashrc, which in turn sources the files in /etc/profile.d. All you would need to do is add lines in your own .bashrc after the line that sources /etc/bashrc and unalias or redefine any aliases that don't suit you.

loadedmind 01-05-2012 01:34 PM

Thanks for your response. What dictates which files get used for defining aliases? Is that /etc/bashrc? If I wanted to use .bash_profile instead of .bashrc, for example, would I simply need to add a line before the ~/.bashrc section of /etc/bashrc?

David the H. 01-05-2012 05:50 PM

Read the INVOCATION section of the bash man page. It details exactly which startup files are used by your distro and their order. Settings made in later files generally overwrite earlier ones of the same name.

Note that it can't take into account any external files sourced into those files though, so you may have to read through each one to find other dependencies.

rknichols 01-06-2012 12:55 AM

As David said, look at the bash manpage to see what files bash will read automatically for various startup conditions (login/non-login, interactive/non-interactive, ...). Beyond that, there is really no substitute for looking at those files to see what they do and what other files they source. Commonly,
~/.bash_profile will source ~/.bashrc
~/.bashrc will source /etc/bashrc
/etc/bashrc will source /etc/profile.d/*.sh
But, all of that is controlled by statements within those files. Unless you really know what you are doing I don't recommend changing the files in /etc. Anything those files set up can be overridden or deleted later in your own ~/.bash_profile and ~/.bashrc.

loadedmind 01-18-2012 05:03 PM

Really appreciate the insight, both of you.


All times are GMT -5. The time now is 05:22 PM.