2. Ordinary and Environment Variables

Ordinary and Environment Variables:

Shell variables are of 2 types: 

1) Environment and 
2) Ordinary variables

Environment Variable:

UNIX environment variables are variables that apply to both the current shell and to any subshells that it creates (for example, when you send a job to the background or execute a script). If you change the value of an environment variable, the change is passed forward to subsequent shells, but not backward to the parent shell.

  • Environmental variables are used to provide information to the programs you use.
  • These variables control the behavior of the system.
  • They determine the environment in which the user works.
  • If environment variables are not set properly, the users may not be able to use some commands.
  • Environment variables are so called because they are available in the user's total environment
  • i.e. the sub-shells that run shell scripts and mail commands and editors.
  • Some variables are set by the system, others by the users, others by the shell programs.
  • env command can be used to display environment variables.

For example:

$ env 
HOME=home/kumar 
IFS=' '
LOGNAME=kumar 
MAIL= /var/mail/kumar 
MAILCHECK=60
PATH=/bin:/usr/bin 
PS1='$'
PS2='>'
SHELL=/usr/bin/bash 
TERM= tty1

  1. HOME
    1. This variable indicates the home directory of the current user.
    2. This variable is set for a user by the system admin in /etc/passwd.
  2. IFS
    1. This variable contains a string of characters that are used as word separator in the command line.
    2. The string normally consists of the space, tab and newline characters.
  3. LOGNAME
    1. This variable shows the username.
  4. MAIL
    1. This variable specifies the path to user’s mailbox.
  5. MAILCHECK
    1. This variable determines how often the shell checks the file for the arrival of new mail.
  6. PATH
    1. This variable specifies the locations in which the shell should look for commands.
    2. Usually, the PATH variable can be set as follows:
    3. $PATH=/bin:/usr/bin
  7. PS1 and PS2
    1. The shell has 2 prompts:
    2. The primary prompt $ is the one the user normally sees on the monitor. $ is stored in PS1.
    3. The user can change the primary prompt as follows:
    4. $ PS1="C>"
      1. C> //similar to windows
    5. The secondary prompt > is stored in PS2.
  8. SHELL
    1. This variable specifies the current shell being used by the users.
    2. Different types of shells are:
      1. Bourne shell /bin/sh 
      2. C-shell /bin/csh 
      3. Korn shell /bin/ksh
    3. This variable is set for a user by the system admin in /etc/passwd.
  9. TERM
    1. This variable indicates the terminal type that is used.
    2. Every terminal has certain characteristics that are defined in a separate control file in the terminfo directory.
    3. If TERM is not set correctly, vi will not work and the display will be faulty.

0 Comments:

Post a Comment