env
Display the environment variables
TLDR
Show the environment
Run a program. Often used in scripts after the shebang (#!) for looking up the path to the program
Clear the environment and run a program
Remove variable from the environment and run a program
Set a variable and run a program
Set one or more variables and run a program
Run a program under a different name
SYNOPSIS
env [OPTION]... [NAME=VALUE]... [COMMAND [ARG]...]
PARAMETERS
-i, --ignore-environment
Starts the command with an empty environment. No variables are inherited from the calling shell, except those explicitly set by NAME=VALUE arguments.
-u NAME, --unset=NAME
Removes the variable NAME from the environment before executing the command. This takes precedence over any NAME=VALUE arguments that would otherwise set NAME.
-0, --null
Ends each output line with a 0 (null) byte instead of a newline. This is particularly useful when piping env's output to commands like xargs -0.
--help
Displays a help message and exits.
--version
Outputs version information and exits.
DESCRIPTION
The env command is a versatile utility used to manipulate the environment variables for a subsequent command execution or to display the current environment. It can list all current environment variables, set new variables, modify existing ones, or even clear the entire environment before executing another program. This functionality is crucial for ensuring that a script or application runs with a specific set of environment settings, isolating it from the calling shell's environment, or for debugging issues related to environment variable configuration. It provides precise control over the environment variables passed to child processes.
CAVEATS
env only affects the environment of the command it executes or displays the current environment; it does not modify the environment of the current shell session. Using -i (ignore-environment) can be powerful but may cause unexpected behavior for commands that rely on standard environment variables like PATH, HOME, or LANG.
ENVIRONMENT VARIABLES
Environment variables are key-value pairs that influence the behavior of running processes. They are inherited by child processes. env allows direct manipulation of these variables for a specific process invocation, enabling fine-grained control over execution contexts.
DIFFERENCE WITH 'EXPORT'
While both env and the shell builtin export deal with environment variables, their scope differs.
env modifies or sets variables only for the specific command it executes, or displays them. It does not alter the calling shell's environment.
In contrast, export modifies the environment of the current shell and for any child processes subsequently started from that shell.
HISTORY
The env command is a fundamental utility in Unix-like operating systems, tracing its roots back to early versions of Unix. It is part of the GNU Core Utilities, indicating its long-standing and essential role in system administration and scripting. Its core functionality has remained consistent, adapting to modern usage patterns while retaining its original purpose of environment manipulation.