When you log in, the shell defines your user environment after reading the initialization files that you have set up. The characteristics of your user environment are defined by the values given to your environment variables. You maintain this environment until you log off the system.
The shell uses two types of profile files when you log in to the operating system. It evaluates the commands contained in the files and then executes the commands to set up your system environment. The files have similar functions except that the /etc/profile file controls profile variables for all users on a system whereas the .profile file allows you to customize your own environment.
The shell first evaluates the commands contained in the /etc/profile file and then runs the commands to set up your system environment in the /etc/environment file. After these files are run, the system then checks to see if you have a .profile file in your home directory. If the .profile file exists, it runs this file. The .profile file will specify if there also exists an environment file. If an environment file exists, (usually called .env), the system then runs this file and sets up your environment variables.
The /etc/profile, /etc/environment, and the .profile files are run once at login time. The .env file, on the other hand, is run every time you open a new shell or a window.
This section discusses the following initialization files:
The first file that the operating system uses at login time is the /etc/profile file. This file controls systemwide default variables such as:
The system administrator configures the profile file for all users on the system. Only the system administrator can change this file.
The following example is typical of an /etc/profile file:
#Set file creation mask unmask 022 #Tell me when new mail arrives MAIL=/usr/mail/$LOGNAME #Add my /bin directory to the shell search sequence PATH=/usr/bin:/usr/sbin:/etc:: #Set terminal type TERM=lft #Make some environment variables global export MAIL PATH TERM
See .profile File Format in the AIX Version 4.3 Files Reference for detailed information about the /etc/profile file.
The second file that the operating system uses at login time is the /etc/environment file. The /etc/environment file contains variables specifying the basic environment for all processes. When a new process begins, the exec subroutine makes an array of strings available that have the form Name=Value. This array of strings is called the environment. Each name defined by one of the strings is called an environment variable or shell variable. The exec subroutine allows the entire environment to be set at one time.
When you log in, the system sets environment variables from the environment file before reading your login profile, .profile. The following variables make up the basic environment:
See .environment File in the AIX Version 4.3 Files Reference for detailed information about the /etc/environment file.
The third file that the operating system uses at login time is the .profile file. The .profile file is present in your home ($HOME) directory and enables you to customize your individual working environment. Because the .profile file is hidden, use the li -a command to list it.
After the login program adds the LOGNAME (login name) and HOME (login directory) variables to the environment, the commands in the $HOME/.profile file are executed if the file is present. The .profile file contains your individual profile that overrides the variables set in the /etc/profile file. The .profile file is often used to set exported environment variables and terminal modes. You can tailor your environment as desired by modifying the .profile file. Use the .profile file to control the following defaults:
The following example shows a typical .profile file:
PATH=/usr/bin:/etc:/home/bin1:/usr/lpp/tps4.0/user:: epath=/home/gsc/e3: export PATH epath csh
This example has defined two path variables (PATH and epath ), exported them, and opened a C shell (csh ).
You can also use the .profile file (or if it is not present, the /etc/profile file) to determine login shell variables. You can also customize other shell environments. For example, use the .cshrc file and .kshrc file to tailor a C shell and a Korn shell, respectively, when each type of shell is started.
A fourth file that the operating system uses at login time is the .env file, if your .profile has the following line: export ENV=$HOME/.env
The .env file enables you to customize your individual working environment variables. Because the .env file is hidden, use the li -a command to list it. The .env file contains the individual user environment variables that override the variables set in the /etc/environment file. You can tailor your environment variables as desired by modifying your .env file. The following example shows a typical .env file:
export myid=`id | sed -n -e 's/).*$//' -e 's/^.*(//p'` \ bold=`tput smso` \ norm=`tput rmso` #set prompt: login & system name (reverse video) & path (normal) if [ $myid = root ] then typeset -x PSCH='${bold}#:${norm}\${PWD}> ' PS1="${bold}#:${norm}\${PWD}> " else typeset -x PSCH='>' PS1="${bold}$LOGNAME@$UNAME:${norm}\${PWD}> " PS2=">" PS3="#?" fi export PS1 PS2 PS3 #setup my command aliases alias ls="/bin/ls -CF" \ d="/bin/ls -Fal | pg" \ rm="/bin/rm -i" \ up="cd .."
Note: When modifying the .env file, ensure that newly created environment variables do not conflict with standard variables such as MAIL, PS1, PS2, and IFS.