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
SYNOPSIS
env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]
PARAMETERS
-i, --ignore-environment
Start with an empty environment.-u, --unset=NAME
Remove the variable named NAME from the environment.-0, --null
end each output line with NUL, not newline--help
Display help message and exit.--version
Output version information and exit.NAME=VALUE
Set the environment variable NAME to VALUE.COMMAND [ARG]...
Execute COMMAND with the modified environment. If no COMMAND is given, print the current environment.-
After this option, no further option processing occurs. Any remaining arguments are interpreted directly as command names, which allows you to pass options to the command without them being interpreted as env options.
DESCRIPTION
The env
command is a fundamental utility in Linux used to view, modify, and execute programs within a custom environment. It allows users to inspect the current environment variables, set new variables for a specific command invocation, or even clear the entire environment before executing a program. The command's primary function is to manage the set of key-value pairs that influence the behavior of processes, such as the search path for executables (PATH
), the terminal type (TERM
), and user-specific configurations. It is particularly useful for creating isolated environments or for running programs with different configurations than the default system settings. Understanding env
is essential for effective scripting and managing software dependencies. Its simplicity hides a powerful ability to customize the execution context of applications.
CAVEATS
Some systems may impose limits on the total size of the environment, potentially leading to errors if you set too many variables or variables that are too large. Also be aware that the `env` command only affects the environment of the specified command and its child processes. It does not permanently alter the user's shell environment.
EXAMPLES
env
by itself lists the current environment variables.
env -i COMMAND
executes COMMAND with an empty environment.
env NAME=VALUE COMMAND
executes COMMAND with NAME set to VALUE.
env -u NAME COMMAND
executes COMMAND without NAME in environment.
HISTORY
The `env` command has been a standard part of Unix-like operating systems for many years, appearing in early versions of POSIX.
Its initial purpose was to provide a way to isolate and control the environment in which commands are executed, which is useful for scripting, testing, and managing application dependencies. Over time, its functionality has remained largely consistent, focusing on the core ability to manipulate environment variables.