Initialization Files

7 241 0
Initialization Files

Đang tải... (xem toàn văn)

Thông tin tài liệu

Initialization Files Objectives Upon completion of this module, you should be able to: • Name the different initialization files for the Bourne Again, Bourne, Korn, and C shells. • Define the purpose of initialization files • Describe where the initialization files are located and what types of settings can be defined • Set the ENV variable to enable the .kshrc file to be read Discussion – Certain types of information, such as your default printer, are set each time you log in. What other types of customizable settings could be set at the beginning of each session? Features of Initialization Files Overview Initialization files contain a series of commands and variable settings that are executed when a shell is started. These files customize the environment for the system and the user. There are two levels of initialization files. The first level is system-wide. System initialization files are maintained by a system administrator and reside in the /etc directory. The second level is user-specific initialization files that reside in a user’s home directory. These files are listed in Table 11-1. Table 11-1 User-Specific Initialization Files Shell System-Wide User-Specified Read First) (Read Second) Bourne-Again 1. /etc/profile 2. $HOME/.bash_profile 3. $HOME/.bashrc Bourne 1. /etc/profile 2. $HOME/.profile Korn 1. /etc/profile 2. $HOME/.profile ENV=$HOME/.kshrc;export ENV 3. $HOME/.kshrc C 1. /etc/.login 2. $HOME/.login 3. $HOME/.cshrc 4. $HOME/.logout Note –$HOME is the user’s home directory. When a predefined environment variable is placed in one of the system-wide initialization files, it is recognized globally in any shell or subshell. Users can customize many of these variables for their own environment by placing them in the initialization files in their home directory. To make the customizations available to all subsequent shells, the variable must be exported. Unlike variables, commands cannot be exported. If commands are used in the initialization files, they must be placed in the secondary initialization files in order to be read each time a subshell is opened. The /etc/profile Script When a user logs in, the system reads the /etc/profile file first, and then it reads the user’s ~/.bash_profile file. This means that the user’s preferences for variable settings can override the default settings that appear in the /etc/profile file. The /etc/profile file: • Exports environment variables such as LOGNAME for login name • Exports PATH for the default command path • Sets the variable TERM for the default terminal type • Displays the contents of the /etc/motd file • Sets the default file creation permissions • Checks if you have mail and will print a mail message upon login This file is maintained by the system administrator. User-Specific Initialization Files Login Sequence When you log in to your system, the system and user’s initialization files for the appropriate shell are read, and the tasks defined in the initialization files are executed. The initialization files provide great flexibility to the user for customizing their environment. Generally, these files are set up as templates by the system administrator, and then modified by the user. The user-specific initialization file(s) are stored in the home directory of the user. These initialization files can perform all or part of the following: • Set the default prompt • Define the default printer • Set default permissions • Set the default terminal type used by vi and other tools • Tell the shell where to look for new mail • Set noclobber to prevent overwriting of files during redirection • Set the command path to the user’s specification • Set up custom commands When you first log in to the system, you are placed in the default shell as defined by the /etc/passwd entry for your account. The initialization files are read as shown in Table 11-2. The .bash_profile, .profile,.login, .bashrc,.cshrc,.kshrc files are assumed to be in the user’s home directory. Table 11-2 Initialization Files Read Process Shell Read during login Read opening shell Bourne-Again /etc/profile, .bash_profile and .bashrc .bashrc Bourne /etc/profile and .profile Korn /etc/profile, .profile and .kshrc .kshrc C /etc/.login, .cshrc and .login .cshrc Shells The login shell is assigned by the system administrator as part of creating a user account. The login shell determines which initialization files are read during login. Bourne Again Shell The Bourne Again shell uses .bash_profile, .bashrc files to set the user’s environment. When you log in to the system, the .bash_profile file is read. Then, the .bashrc file is read. The .bash_profile file is only read once, while the .bashrc file is read every time a new bash shell is opened. Bourne Shell The Bourne shell uses .profile, a user-specific initialization file to set the user’s environment. The .profile file is only read once during login. Korn Shell The Korn shell uses two user-specific environment files to set the user’s environment: • .profile • .kshrc When you log in to the system, the .profile file is read. Then, if the ENV variable in the .profile file is assigned and exported, the .kshrc file is read. The .profile file is only read once, while the .kshrc file is read every time a new Korn shell is opened. Many Korn shell commands cannot be executed by the Bourne shell and therefore should not be placed in the .profile file. These Korn shell specific commands and features should be placed in the .kshrc file. The contents of the .kshrc file can include  A customized prompt  Custom variables  Aliases To have the system reread the .kshrc or .profile file after changes have been made, the user can either log out and log back in, or type the following from the command line: $ . ~/.kshrc $ . ~/.profile C Shell The C shell uses two user-specific environment files to set the user’s environment:  .login  .cshrc Both files are located in the user’s home directory. The .login file is read only when a user logs in to the system, whereas the .cshrc file is read each time a user invokes the C shell. To have the system reread the .login or .cshrc file after changes have been made, the user can either log out and log back in, or type the following from the command line: % source ~/.login % source ~/.cshrc The ENV Environment Variable The ENV variable defines the path to the .kshrc file. This variable must be stored in the .profile file to inform the system that the.kshrc file exists and is to be read when creating a Korn shell. Command Format ENV=$HOME/ filename; export ENV Setting the .kshrc Variable This command sets the environment variable to point to the .kshrc file in the $HOME directory. HOME is a variable that is defined by the system to be the absolute path to the user’s login directory. Preceding the HOME variable with the dollar sign ($) metacharacter enables the system to use the value of HOME in the specified location. $ ENV=$HOME/.kshrc; export ENV When the ENV variable is placed in the .profile file and read by other shells (such as the Bourne shell), it does not act as a pointer to the .kshrc file. This variable has no meaning outside of the Korn shell. Exercise: Setting Initialization Files Exercise objective – In this exercise, you will demonstrate an understanding of the concepts covered in this module. Tasks Write the information requested in the space provided. 1. What is an initialization file? ___________________________________________________________ ___________________________________________________________ ___________________________________________________________ ___________________________________________________________ 2. Where are the user-specific initialization files stored? ___________________________________________________________ 3. Name the user-specific initialization files for the Bourne-Again shell. ___________________________________________________________ ___________________________________________________________ 4. Describe or name at least three settings that can be stored in the .bashprofile or .login initialization file for each shell. ___________________________________________________________ ___________________________________________________________ ___________________________________________________________ Exercise Summary Discussion – Take a few minutes to discuss what experiences, issues, or discoveries you had during the lab exercises.  Manage the discussion here based on the time allowed for this module, which was given in the “About This Course” module. If you find you do not have time to spend on discussion, then just highlight the key concepts students should have learned from the lab exercise. • Experiences  Ask students what their overall experiences with this exercise have been. You might want to go over any trouble spots or especially confusing areas at this time. • Interpretations  Ask students to interpret what they observed during any aspects of this exercise. • Conclusions  Have students articulate any conclusions they reached as a result of this exercise experience. • Applications  Explore with students how they might apply what they learned in this exercise to situations at their workplace. Exercise Solutions Write the information requested in the space provided. 1. What is an initialization file? An initialization file is an environment file that generally resides in the user’s home directory and is used to customize the user’s environment. 2. Where are the user-specific initialization files stored? User-specific initialization files are stored in the user’s home directory. 3. Name the user-specific initialization files for the bash shells. .bash_profile and .bashshrc 4. Describe or name at least three settings that can be stored in the .profile or .login initialization file for each shell. Time zone, terminal type, PATH, user’s login name, default printer, local language, and where shell should look for new mail and environment variables. Check Your Progress Before continuing on to the next module, check that you are able to accomplish or answer the following:  Name the different initialization files for the Bourne Again, Bourne, Korn, and C shells.  Define the purpose of initialization files  Describe where the initialization files are located and what types of settings can be defined  Set the ENV variable to enable the .kshrc file to be read Think Beyond What kinds of settings and customizations would you put into your initialization files at work? . user-specific initialization files stored? User-specific initialization files are stored in the user’s home directory. 3. Name the user-specific initialization files. initialization files are executed. The initialization files provide great flexibility to the user for customizing their environment. Generally, these files

Ngày đăng: 02/10/2013, 09:20

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan