Scope of Shell Variables

There are two types of processes that are involved in any discussion of a multitasking system. The original process, gsh for example, is called a parent process. If gsh invokes a process, such as ls, cp, or mv, that process is called a child process. It is possible for any process to define a variable. These variables will not be made available to other processes unless the program that defined the variable specifically makes them available.

The export command makes variables defined by one process available to its children. See the example gshrc shell script shown in the Section called Customizing the Shell Environment in the Chapter called Getting Started with the GNO Shell. In the case of the shell, most of its variables are exported and, therefore, all shell utilities can read the value of a shell variable. However, programs cannot change the value of a shell variable. In general, executables share their environment with that of the shell, so that a utility can change variables in its parent's environment. This allows communication between programs and the shell.