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