Module 41 env (SV)

Previous Table of Contents Next


Module 41
env (SV)

DESCRIPTION

The external env command creates a new environment for executing a given command. Depending on the options, env either uses the current environment or completely ignores it. If env uses the environment, modifications are made based on the arguments given. After the new environment is set up, the command argument is executed.

COMMAND FORMAT

Following is the general format of the env command.

 env [ - ] [ name=value ... ] [ command [ options ] [ args ] ] 

Options

The only valid option for env is described as follows :

- Do not pass the current environment to the command being executed by env .

Arguments

The following list describes the arguments that may be passed to the env command.

name=value Variables may be assigned values that will be exported for the command to use during execution.
command The command that env executes with the new environment. The options and arguments are those of the command being executed; they are not interpreted by env .

If no arguments are specified, env displays all exported variables.

FURTHER DISCUSSION

Arguments must be of the form variable=value . These arguments are merged into the existing environment. The remainder of the arguments are executed as a normal command. The command executes with the newly defined environment. After the command exits, the environment returns to the state it was before the env command was executed.

The following command shows the changes made to the environment by env :

 cj> env HOME=/tmp TERM=adm5 env      ENV=/u1/ts/mylogin/.kshrc      FCEDIT=vi      HOME=/tmp      LOGNAME=mylogin      MAIL=/usr/mail/mylogin      PATH=:/u1/ts/mylogin/bin:/bin:/usr/bin:/usr/lbin:/usr/local/bin      SHELL=/bin/ksh      TERM=adm5      TMPDIR=/tmp      TZ=CST6CDT      VISUAL=vi 

The env command modifies your HOME and TERM variables and then executes the env command again to show the changes in the new temporary environment.

If you do not wish to have the current environment passed to the command for execution, you can use the - (hyphen) option. Only the variables you define on the env command line will be passed to the command. The following command demonstrates the use of the dash option:

 cj> env - HOME=/tmp TERM=adm5 env      HOME=/tmp      TERM=adm5 

The env command will create a new temporary environment with only the HOME and TERM variables defined.

If no arguments are given, env lists out the current environment with one variable and value per line.

RELATED COMMANDS

Refer to the ksh command described in Module 71.

RELATED FILES

The env command writes to the standard output.

APPLICATIONS

The env command is useful for testing commands in controlled environments. It may be used to execute a command in a new environment without affecting your own personal environment. It is probably used more to display the current environment than as a command executor.

TYPICAL OPERATION

In this activity you use the env command to display your current environment. Begin at the shell prompt.

1.    Type env and press Return to list out your current environment.
 cj> env      ENV=/u1/ts/mylogin/.kshrc      FCEDIT=vi      HOME=/u1/ts/mylogin      LOGNAME=mylogin      MAIL=/usr/mail/mylogin      PATH=:/u1/ts/mylogin/bin:/bin:/usr/bin:/usr/lbin:/usr/local/bin      SHELL=/bin/ksh      TERM=vt100      TMPDIR=/tmp      TZ=CST6CDT      VISUAL=vi 
2.     Turn to Module 118 to continue the learning sequence.


Previous Table of Contents Next

Copyright Wordware Publishing, Inc.


Illustrated UNIX System V
Illustrated Unix System V/Bsd
ISBN: 1556221878
EAN: 2147483647
Year: N/A
Pages: 144
Authors: Robert Felps

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