When a user logs in to a system, the shell initialization files determine the work environment. The shell startup scripts can be modified to set environment variables and directory paths needed by a specific user. These startup scripts are located in the user’s home directory.
When you are setting up user initialization files, it might be important to allow the users to customize their own initialization files. This can be accomplished with centrally located and globally distributed user initialization files called site initialization files. These files let you continually introduce new functionality to all of the user work environments by editing one initialization file. The local initialization file, located in the user’s home directory, allows user-specific configuration.
A local initialization file lets users further customize their own work environment. Site initialization files are located in the /etc directory and can be edited only by root. They are designed to distribute site-wide changes to all user work environments. Individual user initialization files are located in each user’s home directory and can be customized by the owner of that directory. When a user logs in, the site initialization file is run first, and then the initialization file located in the user’s home directory is run.
Note
Do not use system initialization files located in the /etc directory (/etc/profile, /etc/.login) to manage an individual user’s work environment. These are site initialization files, which are considered to be global files and are meant to be generic and used to set work environments for all users. The system will run this startup file first and will then run the user’s startup file located in the home directory.
The most common customizations to shell startup scripts are environment variables. Table 13.8 describes the more common environment and shell variables, including some you might want to customize in a user initialization file.
In the next exercise, we’ll modify the shell environment by changing some of the variables in the shell startup file.
Exercise 13.5 Verifying and Changing a User’s Environment
The following example illustrates how to verify a user’s environment settings and how to change them:
1. |
Log in as the user. This step lets you see the user’s environment as the user will see it. |
2. |
Edit the user’s initialization files. The following steps suggest some changes and show the shell-specific syntax to use. |
3. |
Set the user’s default path to include the home directory as well as directories or mount points for the user’s windowing environment and applications. To change the path setting, add or modify the line for PATH as follows. For the Bourne or Korn shell, the syntax is as follows: PATH=/dirname1:/dirname2:/dirname3:.; export PATH For example, enter the following line in the user’s $HOME/.profile file: PATH=$PATH:/usr/bin:/$HOME/bin:/net/glrr/files1/bin:.;export PATH For the C shell, the syntax is as follows: set path =(/dirname1 /dirname2 /dirname3 .) For example, enter the following line in the user’s $HOME/.cshrc file: set path=($path /usr/bin $HOME/bin /net/glrr/files1/bin .) Note Prefixing $PATH (K shell) or $path (C shell) appends changes to the user’s path settings already set by the site initialization file. When you set the PATH variable with this procedure, initial path settings are not overwritten and lost. Also note the dot (.) at the end of the list to denote the current working directory. The dot should always be at the end of the path, as discussed in Chapter 16. |
4. |
Check that the environment variables are set to the correct directories for the user’s windowing environments and third-party
applications. Type env and press Enter: $ env HOME=/home/bcalkins HZ=100 LOGNAME=bcalkins MAIL=/var/mail/bcalkins MANSECTS=1:1m:1c:1f:1s:1b:2:3:3c:3i:3n:3m:3k:3g:3e:3x11:3 xt:3w:3b:9:4:5:7:8 PATH=/usr/bin SHELL=/bin/sh TERM=sun TZ=EST5EDT $ |
5. |
Add or change the settings of environment variables by entering either of the following lines. For the Bourne or Korn shell, the syntax is as follows: VARIABLE=value;export VARIABLE The following example sets the user’s default mail directory: MAIL=/var/mail/bcalkins;export MAIL For the C shell, the syntax is as follows: setenv VARIABLE value The following example sets the history to record the last 100 commands: set history = 100 |