Customizing User Initialization Files

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.

Table 13.8. Shell and Environment Variable Descriptions
Variable Description
LOGNAME Defines the user’s login name.
HOME Defines the path to the user’s home directory. The cd command uses this variable when an argument is not specified.
SHELL Defines the path to the default shell. This variable wouldn’t normally be modified manually by the user.
LPDEST Sets the user’s default printer.
PWD This variable is set to the current working directory. It changes automatically each time the user changes directories. This variable wouldn’t be modified manually by the user.
PS1 Defines the shell prompt for the Bourne and Korn shells.
PATH (or path in the C shell) Lists, in order, the directories the shell searches to find the program to run when the user types a command. If the directory is not in the search path, users must type the complete pathname of a command.

The default PATH is automatically defined in .profile (Bourne or Korn shell) or .cshrc (C shell) as part of the login process.

The order of the search path is important. When identical commands exist in different locations, the first command found with that name is used. For example, suppose PATH is defined (in Bourne and Korn shell syntax) as PATH=/bin:/usr/bin:/usr/sbin:$HOME/bin and a file named sample resides in both /usr/bin and /home/ glenda/bin. If the user types the command sample without specifying its full pathname, the version found in /usr/bin is used.
prompt Defines the shell prompt for the C shell.
TERM (or term in the C shell) Defines the terminal. This variable should be reset in /etc/profile or /etc/.login. When the user invokes an editor, the system looks for a file with the same name as the definition of this environment variable. The system searches the directory /usr/share/lib/terminfo to determine the terminal characteristics.
MAIL Sets the path to the user’s mailbox.
MANPATH Sets the search path for system manual pages.
umask Sets the default user mask.

Tip

Some users find it helpful to make their login name, the hostname, and the current directory part of the prompt. Here’s how to set it up:
PS1="$(whoami)@$(hostname) [$PWD] #" 

The resulting prompt is as follows:
root@ultra5 [/usr/bin] # 



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 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset