env — Display or set environment variables for a process

Format

Description

If you enter env with no arguments, it displays the environment variable that it received from its parent (presumably the shell).

Arguments of the form variable=value let you add new environment variables or change the value of existing environment variables.

If you specify command, env calls command with the arguments specified with the argument argument that appear on the command line, passing the accumulated environment variable to this command. The command is run directly as a program found in the search path, and is not interpreted by a shell.

In a double-byte locale, environment variable values can contain double-byte characters. The equal sign (=) must be single byte.

Options

env supports the following two options, both of which have the same effect.
–i
Specifies that the environment variable inherited by env not be used.
Specifies that the environment variable inherited by env not be used.

Examples

Start of change
  1. Compare the output of the following two examples:
    env foo=bar env
    env –i foo=bar env
  2. Compare the output of the following example:
    env - echo $PATH                                           
    	.:/usr/lpp/Printsrv/bin:/bin:/usr/sbin  
End of change The variable $PATH appears to still be valid but is resolved first by the shell before the initial env command is run to clear the environment variables with the - or -i option. For more information, see the section on using substitutions in commands in z/OS UNIX System Services User's Guide.

Localization

env uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_CTYPE
  • LC_MESSAGES
  • NLSPATH

See Localization for more information.

Exit values

0
Successful completion.
1
Failure due to any of the following situations:
  • Not enough memory
  • Name is too long
2
Incorrect command-line argument.
126
env found command but could not invoke it.
127
env could not find command.

Portability

POSIX.2, X/Open Portability Guide, UNIX System V.

printenv on Berkeley UNIX systems works like env.

Related information

env, sh