Shell Start-Up Files

Team-Fly    

Solaris™ Operating Environment Boot Camp
By David Rhodes, Dominic Butler
Table of Contents
Chapter 5.  Shells


We have seen that the shell automatically defines some environment variables at login time. The values assigned to these variables are obtained from fields within the password file, but how do the others get set up?

These need to be assigned at login time, but to save this being done manually every time you log in, each shell provides a method of automating this process using files called "profiles." If the system administrator wants to set specific environment variables that will apply to all users on the system, the variables would be set up in the system-wide profile, which is /etc/profile.

The shell executes this file every time a user logs in. It will generally contain assignments for such variables as $PATH (so users have access to all the standard places programs will be stored) and $PS1 (so users can have a prompt that is slightly more useful that a dollar sign).

If the administrator wants to set up specific variables for specific users or groups of users, this would be done in the user's personal profile. This is located in the user's home directory and is called .profile. Since the filename begins with a dot, it is referred to as a "hidden file." This means that the ls command will not display it unless the "-a" option is used and wildcards will not match it unless the leading dot is specified.

Some companies have a policy that users are not allowed to make changes to their personal profiles, in which case the permissions (see Chapter 4, "Permissions and All That") will be set to prevent them from doing so. The system administrator may even create each users .profile as a link (see Chapter 6, "The Filesystem and Its Contents") to a master profile to ease the process of making changes to users' profiles. Other companies will have no such policy so that users can update this file and customize their environment as they see fit. Because the personal profile is executed after the system-wide profile, anything set in the system profile can be unset or overridden (unless it has been made read-only by the system administrator).

The files /etc/profile and ~/.profile are login shell start-up files. They are executed every time a login shell is started, but once you have logged in they will not be re-executed even if you run another shell process. The ability to execute a file every time a shell starts regardless of whether it is a login shell is available within the Korn Shell if the environment variable $ENV is set. For example, if you set ENV=~/.login then each time a new subshell was spawned, the file called .login in your home directory would be executed.

The login profiles are executed in the following order: /etc/profile, then ~/.profile, and finally ~/.login (provided that is what you set $ENV to contain). It is not compulsory for any of these files to exist. Once you are logged in, every time you spawn a subshell the ~/.login file will be re-executed. You will probably find that, in practice, $ENV is rarely used, but you could use it, for example, to warn users that they have entered a subshell.

If you are using a different shell the above will not necessarily apply, but for most shells /etc/profile will be run first followed by a profile for the user. The C Shell (csh) will first source /etc/.login (rather than /etc/.profile) and then will look for a file called .login in your home directory. This is the equivalent to the Korn Shell .profile in that it will only run at login and not if you execute the C Shell from within another shell. In addition, in the ~/.login file the C Shell will look for a ~/.cshrc (C Shell run commands) file. If this exists, it will be run each time you spawn a new C Shell (similar to the $ENV of the Korn Shell). The order for the C Shell is /etc/.login, followed by ~/.cshrc, and finally ~/.login.


    Team-Fly    
    Top
     



    Solaris Operating Environment Boot Camp
    Solaris Operating Environment Boot Camp
    ISBN: 0130342874
    EAN: 2147483647
    Year: 2002
    Pages: 301

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net