Previous Table of Contents Next

Module 47
export (sh, ksh)


The internal export command places variables in the shell environment. The shell maintains two sets of variables, the local variables and the global or environment variables. Local variables are only known to the current shell. Environment variables are know by the current shell and are available to all processes started by the current shell. The export command marks local variables to become environment variables.

COMMAND FORMAT Following is the general format of the export command.

    export [ variable ... ]

Arguments The arguments for the export command are variables that you wish to place in the shell environment. You can export a variable without setting it to a value. When it does become set (a value is assigned), it will automatically be exported to the environment.

FURTHER DISCUSSION Exported variables exist in the environment space of the shell process. When the shell executes a new child process (subprocess) it passes the environment to the new process. The environment consist only of variables that have been exported. By using exported variables you can pass global information to any subprocess. Whether the environment is used by the subprocess depends on the subprocess.

Subprocesses cannot change the environment of a parent process. They can change their environment but the changes cannot be passed back to the parent.

If export is executed without any arguments, it lists out all exported variables. If you are in a subshell and use export with no arguments, only the variables that have been exported in the subshell are listed. To list all exported variables that were passed to a subshell use the env command described in Module 41.

TIP:  It is not unusual to have control characters assigned to variables. These can cause your output to be garbled when you display them using the export command. To remove or convert them for display purposes use the following command.

    export | col


    export | cat -v

RELATED COMMANDS Refer to the env command described in Module 41 and the set command described in Module 118. The csh uses setenv to perform the same function, see Module 119.

RELATED FILES The export command writes to the standard output when no arguments are given.


The export command is used to allow information to be passed from a parent process to a child process. For example, the vi editor uses the environment SHELL and TERM variables to know what type of terminal it is working with and which shell to invoke when you request one.


In this activity you use the export command to place the COLUMNS variable in the environment. You then start a subshell and view the exported commands using export. If you are using the csh, skip to the next module. Begin at the shell prompt.

1.  Type export and press Return. Notice all of your environment variables are displayed.
2.  Type export COLUMNS=80 and press Return. No response is sent to your terminal.
3.  Type export and press Return. Notice now the COLUMNS variables is in the environment.
    cj> export
4.  Turn to Module 41 (SV), Module 118 (BSD) to continue the learning sequence.

Previous Table of Contents Next