• No results found

The .profie file

In document Unix Shell Scripting (Page 46-54)

A fte r a u se r lo g s in a n d a s p a rt o f sta rtin g u p th e u se r‘s sh e ll, two profile files are executed. The first is the system profile /etc/profile, which is run by every user, and the second is the .profile in the user home directory, which is only run by the user who owns it.

The .profile contains a sequence of commands that help you customize your environment. Because the .profile is read each time you start a new Korn shell, the commands you put in this file to customize your environment will be executed each time you start a new ksh.

These commands can include, but are certainly not limited to, the following:

1. aliases

2. terminal control characteristics

3. creation/definition of shell environment variables (including your prompt)

The first file that the operating system uses at login is the /etc/environment file. This file contains variables specifying the basic environment for all processes and can only be changed by the system administrator.

The second file that the operating system uses at login time is the /etc/profile file. This file controls system-wide default variables such as the mail messages and terminal types.

/etc/profile can only be changed by the administrator.

The .profile file is the third file read at login time. It resides in a user's login directory and enables a user to customize their individual working environment. The .profile file overrides commands run and variables set and exported by the /etc/profile file.

Ensure that newly created variables do not conflict with standard variables such as MAIL, PS1, PS2 and so forth.

At startup time the shell checks to see if there is any new mail in /usr/spool/mail/$LOGNAME. If there is then MAILMSG is echoed back. In normal operation, the shell checks periodically.

The ENV="$HOME/.kshrc" variable will cause the file $HOME/.kshrc to be run every time a new Korn shell is explicitly started. This file will usually contain Korn shell specifics.

The .profile file is read only when the user logs in.

Be aware that your .profile file may not be read if you are accessing the system through CDE (the Common Desktop Environment). By default, CDE instead uses a file called .dtprofile. In the CDE environment, if you wish to use the .profile file, it is necessary to uncomment the DTSOURCEPROFILE variable assignment at the end of the .dtprofile file.

Module 5 Overview

The tilde (~) Expansion:

The C shell provides an easy way to abbreviate the pathname of your home directory. When the tilde symbol (~) appears at the beginning of a word in your command line, the shell replaces it with the full pathname of your login directory.

Example:

% mv file ~/newfile

Is the abbreviated way of typing this

% mv file $home/newfile The whence Command

The whence command can be used to determine exactly where the command you specify is located. For instance, it may be a command located on the disk drive, it may be an alias, or it may be built-in to the Korn shell. whence reports the proper location.

whence

$ whence ls <works with basic commands>

/bin/ls

$ whence dir <works with aliases>

/bin/ls -al | more

$ whence echo <works with built-in commands>

echo

Aliases

Aliases in the Korn shell allow you to create your own commands. You can simply rename existing commands, or you can group commands together to create entirely new commands. This feature is also available in the C shell, but the command syntax is slightly different.

The ksh syntax for alias commands:

alias name='value'

The ENV variable specifies a Korn shell script to be invoked every time a new shell is created. The shell script in this example is .kshrc (which is the standard name used), but any other filename can also be used.

The difference between .profile and .kshrc is that .kshrc is read each time a subshell is spawned, whereas .profile is read once at login.

You can also set the following variable in $HOME/.profile:

EDITOR=/usr/bin/vi export EDITOR

It will do the same thing that the set -o vi command does as shown in the example.

The Korn shell sets up a number of aliases by default. Notice that the history and r commands are in fact aliases of the fc command. Once this alias is established, typing an r will reexcute the previously entered command.

To carry down the value of an alias to subsequent subshells, the ENV variable has to be modified. The ENV variable is normally set to $HOME/.kshrc in the .profile file (although you can set ENV to any shell script). By adding the alias definition to the .kshrc file (by using one of the editors) and invoking the .profile file, the value of the alias will be carried down to all subshells, because the .kshrc file is run every time a Korn shell is explicitly invoked.

The file pointed to by the ENV variable should contain Korn shell specifics.

The unalias command will cancel the alias named. The names of the aliases specified with the unalias command will be removed from the alias list.

The /etc/environment file contains default variables set for each process.

Only the system administrator can change this file. PATH is the sequence of directories that is searched when looking for a command whose path name is incomplete.

TZ is the time zone information.

LANG is the locale name currently in effect.

LOCPATH is the full path name of the location of National Language Support information, part of this being the National Language Support Table.

NLSPATH is the full path name for messages.

Module 6

In document Unix Shell Scripting (Page 46-54)

Related documents