3.1 Environment and Shell Variables

   

3.1 Environment and Shell Variables

When a shell executes a command, UNIX creates a process in memory for that command. This process is called the child process of the shell. Because the shell created this process, the shell is called the parent process of the command process.

You can also invoke a shell within another shell. The newly created shell is the child shell. You will be writing shell scripts when you move to the fourth section of the book. These shell scripts are executed within the parent shell as child processes.

All child processes inherit environment variables from their parent (the shell). On the other hand, shell variables are set locally by the shell and are not visible to any child process. Each child gets a copy of the environment variables and is allowed to make changes to these variables. But it should be kept in mind that these changes are local to the child process and can't reflect back. This means that changes made to the environment variables are lost as soon as the child process finishes. Or you can say that a child process can't make changes to the parent variables. The differences between shell and environment variables are presented in Table 3-1.

Table 3-1. Comparison of Shell and Environment Variables
Environment Variables Shell Variables
Also called global variables Also called local variables
Inherited by all child processes Not inherited by children
Usually contain system-specific information Usually used to keep temporary values in shell programs

   
Top


HP Certified
HP Certified: HP-UX System Administration
ISBN: 0130183741
EAN: 2147483647
Year: 2000
Pages: 390
Authors: Rafeeq Rehman

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