Previous | Table of Contents | Next |
DESCRIPTION
The internal setenv command sets an environment variable to a given value. This allows you to use a meaningful name to contain a value. The value can be changed as required. All variables are exported to subshells.
These variables are placed in the shell s 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 known by the current shell and all processes started by the current shell.
The unsetenv command removes a variable from the environment. The value and the variable name are discarded.
COMMAND FORMAT
Following is the general format of the setenv command.
setenv setenv variable setenv variable=value unsetenv variable_pattern
Arguments
The following list describes the arguments that may be passed to the setenv command.
variable | A word used to store a value. |
value | The alpha, numeric, or alphanumeric value stored in a given variable. |
variable_pattern | A pattern expanded by the shell which removes all variables that match it. |
If no argument is given all environment variables are displayed. |
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 consists only of variables that have been exported. By using exported variables you can pass global information to any 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 setenv is executed without any arguments, on some systems, it lists out all exported variables; on others, it returns an error. If you are in a subshell and use setenv with no arguments, only the variables that have been exported in the subshell are displayed. To list all exported variables that were passed to a subshell use the printenv command described in Module 107.
Automatically Exported Variables
The commonly used csh (local) variables path , term , and user are automatically exported to the environment variables PATH, TERM, and USER. This allows you to perform a set variable= value or a setenv VARIABLE value.
RELATED COMMANDS
Refer to the set command described in Module 118 and the printenv command in Module 107.
APPLICATIONS
The setenv command is used to allow information to be passed from a parent process to a child process. For example, the vi editor uses the environmental SHELL and TERM variables to know what type of terminal it is working with and which shell to invoke when you request one.
TYPICAL OPERATION
In this activity you use the setenv command to place the COLUMNS variable in the environment. You then start a subshell and view the exported commands using setenv . Begin at the shell prompt. The setenv command places these and other variables in the environment that is passed to other processes.
cj> printenv . . . COLUMNS=80
Previous | Table of Contents | Next |