Bourne shell environment

All variables (with their associated values) known to a command at the beginning of its execution constitute its environment. This environment includes variables that a command inherits from its parent process and variables specified as keyword parameters on the command line that calls the command.

The shell passes to its child processes the variables named as arguments to the built-in export command. This command places the named variables in the environments of both the shell and all its future child processes.

Keyword parameters are variable-value pairs that appear in the form of assignments, normally before the procedure name on a command line (but see also the flag for the set command). These variables are placed in the environment of the procedure being called.

See the following examples:
  • Consider the following procedure, which displays the values of two variables (saved in a command file named key_command):
    # key_command
    echo $a $b
    The following command lines produce the output shown:
    Input                              Output
    a=key1   b=key2  key_command       key1 key2
    a=tom    b=john  key_command       tom john

A procedure's keyword parameters are not included in the parameter count stored in $#.

A procedure can access the values of any variables in its environment. If it changes any of these values, however, the changes are not reflected in the shell environment. The changes are local to the procedure in question. To place the changes in the environment that the procedure passes to its child processes, you must export the new values within that procedure.

See the following examples:
  • To obtain a list of variables that are exportable from the current shell, type the following:
    export
  • To obtain a list of read-only variables from the current shell, type the following:
    readonly
  • To obtain a list of variable-value pairs in the current environment, type the following:
    env

For more information about user environments, see /etc/environment file.