Working with Solaris Shell Initialization Files - .profile, .kshrc, cshrc, .login, .dtprofile
Working With User Initialization Files
This post describes the Solaris 10 OS default initialization files of the Bourne shell, the Korn shell, and the C shell. Based on the shell, there might be either one or two default initialization files in your home directory that enable you to customize your working environment.
The table below defines the initialization files for the three primary shells in the Solaris 10 OS.
Shell | System-wide Initialization Files | Primary User Initialization Files Read at Login | User Initialization Files Read When a New Shell Is Started | Shell Path Path |
---|---|---|---|---|
Bourne | /etc/profile | $HOME/.profile | N/A | /bin/sh |
Korn | /etc/profile | $HOME/.profile and $HOME/.kshrc | $HOME/.kshrc | /bin/ksh |
C | /etc/.login | $HOME/.cshrc and $HOME/.login | $HOME/.cshrc | /bin/csh |
Bourne Shell Initialization File
The .profile file is an initialization file that you define in your home directory. The login shell executes the .profile file when you log in. You can customize environment variables and terminal settings in the .profile file to modify your working environment. You can also instruct the system to initiate applications in the .profile file.
Korn Shell Initialization Files
The Korn shell employs two initialization files. They are the .profile file and the .kshrc file.
The ~/.profile File
The .profile file is an initialization file that resides in your home directory. The login process runs the .profile file when you log in. You can customize environment variables and terminal settings in the this file to modify your working environment. You can also instruct the system to initiate applications in the .profile file.
The ~/.kshrc File
The .kshrc file in your home directory contains shell variables and aliases. The system executes the .kshrc file every time you log in and when a ksh sub-shell is started. This file is used to define Korn shell specific settings. To use it, the ENV variable must be defined in the .profile file.
You typically configure the following settings in the .kshrc file:
- Shell prompt definitions (PS1 and PS2)
- Alias definitions
- Shell functions
- History variables
- Shell options (set -o option )
When you make changes to your individual initialization files, the changes take effect the next time you log in. However, if you want the changes to take effect immediately, you can source the .profile file and the .kshrc file using the dot (.) command.
$ . ~/.profile
$
$ . ~/.kshrc
C Shell Initialization Files
The C shell employs two initialization files. They are the .cshrc file and the .login file.
The ~/.cshrc File
The .cshrc file is an initialization file that you define in your home directory. The login shell executes the .cshrc file when you log in. You can customize environment variables and terminal settings in the .cshrc file to modify your working environment. You can also instruct the system to initiate applications in the .cshrc file.
You typically configure the following settings in the .cshrc file:
- Shell prompt definitions (PS1 and PS2)
- Alias definitions
- Shell functions
- History variables
- Shell options (set option)
The ~/.login File
The .login file in your home directory has the same functionality as the .cshrc and is there for legacy reasons.
When you make changes to your individual initialization files, the changes take effect the next time you log in. However, if you want the changes to take effect immediately, you can source the .cshrc file and the .login file by using the source command.
$ source ~/.cshrc
$
$ source ~/.login
The ~/.dtprofile File
Another initialization file, called .dtprofile, resides in your home directory. The .dtprofile file determines generic and customized settings for the desktop environment. Your variable settings in the .dtprofile file can overwrite any default desktop environment settings. The desktop environment generates a .dtprofile file for your home directory the first time you log in to the desktop environment.
NOTE: If the DTSOURCEPROFILE variable is set to true, then the dtlogin causes the shell to read the .profile file. If this variable does not exist or it is not set to true, then the .profile file is not read by the shell.
Each time you log in to the desktop environment, the shell reads the .dtprofile file first, your .profile file next, and then your .kshrc file. The shell reads the .profile and .kshrc files again when you open a console window. The shell also reads the .kshrc file when you open a terminal window in the desktop environment.
Configuring the $HOME/.profile File
You can configure the ENV variable in the $HOME/.profile file to instruct the login process to execute the file referenced by the ENV variable. To configure this variable, edit the $HOME/.profile file and insert the following lines:
$ ENV=$HOME/.kshrc
$ export ENV
To verify that the changes were applied, you can either re-run the file or log out and log back in again.
Configuring the $HOME/.kshrc File
The $HOME/.kshrc file contains Korn shell specific settings. To configure the PS1 variable, edit the $HOME/.kshrc file and insert the following lines:
$ PS1=”1hostname‘ $”
$ export PS1
To verify that the changes were applied, you can either re-run the file or log out and log back in again.