Environment

An important Unix concept is the environment, which is defined by environment variables. Some are set by the system, others by you, yet others by the shell, or any program that loads another program.

A variable is a character string to which we assign a value. The value assigned could be a number, text, filename, device, or any other type of data.

For example, first we set a variables TEST and then we access its value using echo command:

$TEST="Unix Programming"
$echo $TEST
Unix Programming
Note that environment variables are set without using $ sign but while accessing them we use $sign as prefix. These variables retain their values until we come out shell.

When you login to the system, the shell undergoes a phase called initialization to set up various environment. This is usually a two step process that involves the shell reading the following files:

/etc/profile

profile

The process is as follows:

The shell checks to see whether the file /etc/profile exists.

If it exists, the shell reads it. Otherwise, this file is skipped. No error message is displayed.

The shell checks to see whether the file .profile exists in your home directory. Your home directory is the directory that you start out in after you log in.

If it exists, the shell reads it; otherwise, the shell skips it. No error message is displayed.

As soon as both of these files have been read, the shell displays a prompt:

$
This is the prompt where you can enter commands in order to have them execute.

Note - The shell initialization process detailed here applies to all Bourne type shells, but some additional files are used by bash and ksh.