From: Floyd Davidson <floyd@ptialaska.net> Subject: Re: Aliases Date: 03 Dec 2002 11:34:31 -0900 References: <asi59v$sra$1@arcturus.ciril.fr>
<3dec9b6c$0$2764$afc38c87@news.optusnet.com.au>
<asicb2$85c$1@arcturus.ciril.fr> radilla@mines.u-nancy.fr (Giovanni Radilla) wrote: >Thank you for your help on both of my questions. >For this one I still don't know the answer. Here >is the file /etc/profile: > >---->[BEGIN] > ># /etc/profile -*- Mode: shell-script -*- [snip]
>for i in /etc/profile.d/*.sh ; do
> if [ -x $i ]; then
> . $i
> fi
>done
[snip]
>where are the aliases?
Read the man page for bash, and do "/INVOCATION" about three
times to find the subsection which describes how bash reads
init files.
A "login" shell (as opposed to a subshell) sources /etc/profile
first, and then sources the first of these files that it can
find,
~/.bash_profile
~/.bash_login
~/.profile
A login shell does *not* source ~/.bashrc, and hence if you do not have a command to source it in whichever of the above three files you use, nothing you have in ~/.bashrc file will affect your login shell! Also note that aliases are _not_ inherited by subshells, hence an alias defined in /etc/profile or in ~/.bash_profile will not exist in a subshell (for example in an xterm running bash unless they are all configured to be login shells). All of this make sense and works correctly *if* your init files are used properly. /etc/profile should be used to set up a system-wide bare minimum interactive shell environment. It is *not* the place to define aliases! It should define environment variables that are unique to each system (ones which a user would not likely want to change), or which are necessary for an interactive login to function. Hence PATH, MANPATH, PS1, PS2, and things like that are all that should be set there. Each user should choose one of the three files to be sourced by a login shell, and use it to add to or adjust what is in /etc/profile. Environment variables that are unique to this user, but that will always be the same in all shells can be set in this file, but it is actually easier to not do that. What *must* be in this file are any terminal configuration setup commands which need to only be executed one time per login (and not every time a subshell is invoked). That would be something like "stty erase ^H", for example. Also commands which add to variables, and hence should only be done once, can be put in this file: PATH=~/bin:$PATH In addition, non-interactive shells (shells used to run scripts, for example) will source whatever file is set for BASH_ENV, so that should be set. And if all aliases are set in ~/.bashrc, a command to read it should be used. Hence ~/.bash_profile might look like this, stty erase ^H export BASH_ENV=~/.bashrc export PATH=~/bin:$PATH . ~/.bashrc And then you can put all of your function definitions, environment variables, and aliases into ~/.bashrc and expect to see them correctly in any shell you invoke! -- Floyd L. Davidson <http://www.ptialaska.net/~floyd> Ukpeagvik (Barrow, Alaska) floyd@barrow.com
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar