Setting Up Shell Initialization Files

As system administrator, when setting up a user’s home directory, you also need to set up the shell initialization files for the user’s login shell (also called user initialization files). A shell initialization file is a shell script that runs automatically each time the user logs in. The initialization file will set up the work environment and customize the shell environment for the user. The primary job of the shell initialization file is to define the user’s shell environment, such as the search path, environment variables, and windowing environment. Each UNIX shell has its own shell initialization file (or files) located in the user’s home directory. This is described next.

C Shell Initialization Files

C shell initialization files run in a particular sequence after the user logs in to the system. For the C shell, initialization files are run in the following sequence:

1.
Commands in /etc/.login are executed.

2.
Commands from the $HOME/.cshrc file (located in your home directory) are executed. In addition, each time you start a new shell or open a new window in CDE, commands from the $HOME/.cshrc are run.

3.
The shell executes commands from the $HOME/.login file (located in your home directory). Typically, the $HOME/.login file contains commands to specify the terminal type and environment.

4.
When the shell terminates, it performs commands from the $HOME/ .logout file (if it exists in your home directory).

5.
Finally, when startup processing is complete, the C shell begins reading commands from the default input device, the terminal.

Bourne Shell Initialization Files

Bourne shell initialization files run in a particular sequence after the user logs in to the system. For the Bourne shell, initialization files are run in the following sequence:

1.
Commands in /etc/profile are executed.

2.
Commands from the $HOME/.profile file (located in your home directory) are executed. Typically, the $HOME/.profile file contains commands to specify the terminal type and environment.

3.
Finally, when startup processing is complete, the Bourne shell begins reading commands from the default input device, the terminal.

Korn Shell Initialization Files

Korn shell initialization files run in a particular sequence after the user logs in to the system. For the Korn shell, initialization files are run in the following sequence:

1.
Commands in /etc/profile are executed.

2.
Commands from the $HOME/.profile file (located in your home directory) are executed. Typically, the $HOME/.profile file contains commands to specify the terminal type and environment.

3.
If the $HOME/.kshrc file is present, commands located in this file are executed. In addition, this initialization file gets read (and the commands get executed) every time a new Korn shell is started after login.

4.
Finally, when startup processing is complete, the Korn shell begins reading commands from the default input device, the terminal.

Solaris 9 also includes, as part of the operating environment, the bash and tcsh shells, which were previously available on a companion CD-ROM of other software. These shells are gaining popularity with system administrators and contain extra options and functions. Further details about these shells and their additional functionality can be found by consulting the manual pages for each.

Note

Initialization files are executed in the order specified for each of the preceding shells, except when logging in to the common desktop environment (CDE). As described in Chapter 25, “Administration and Configuration of CDE,” the $HOME/.dtprofile file is also run. If the DTSOURCEPROFILE variable is not set to TRUE in the .dtprofile, the $HOME/.profile will not be run.

When using CDE, I’ve also found it necessary to add the following lines in the $HOME/.profile to get the .kshrc file to work properly in the Korn shell:

set –ha 
ENV=$HOME/.kshrc 

Without this entry, aliases and environment variables might not get passed to subshells (additional shells spawned by the Korn shell). Therefore, when opening a new window in CDE, alias and environment variables are set in the initial shell but are not set in subsequent shells even though they are listed in the $HOME/.kshrc file. The preceding entries will fix this problem.


When a user logs in to the system, the user’s login shell is invoked. The shell program looks for its initialization files in the order previously listed for each shell. The shell program then executes the commands contained in each file and, when finished, displays the shell prompt on the user’s screen.

Default user initialization files (such as .cshrc, .profile, and .login) are created automatically in the user’s home directory when a new user account is added. The system administrator can predefine the contents of these files or can choose to use the system default files. The Solaris 9 system software provides default user initialization files for each shell in the /etc/skel directory on each system. These files are listed in Table 13.7.

Table 13.7. Default Initialization Files
Name Description
local.cshrc The default .cshrc file for the C shell
local.login The default .login file for the C shell
local.profile The default .profile file for the Bourne and Korn shells

You can use these initialization files as a starting point and modify them to create a standard set of files that will provide a work environment common to all users. You can also modify them to provide the working environment for different types of users.

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

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