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]...]
Without COMMAND, print the current environment.
PARAMETERS
-i, --ignore-environment
Start with an empty environment
-u, --unset=NAME
Remove specified variable from environment
-C DIR, --chdir=DIR
Change working directory to DIR before executing command
-S STRING, --split=STRING
Use STRING as separator for multiple commands
-v, --verbose
Print verbose information
--help
Display help and exit
--version
Output version information and exit
DESCRIPTION
The env command executes a specified program in a customized environment. It allows setting, unsetting, or clearing environment variables before running the command. If no command is provided, env simply prints all current environment variables, one per line, in NAME=VALUE format.
Common uses include temporarily overriding variables for scripts, creating clean environments with -i, or unsetting specific variables. For example, env -i PATH=/bin:/usr/bin command runs command in an empty environment except for PATH.
It supports changing the working directory with -C and verbose output with -v. A lone - or -- implies -i. env is part of GNU coreutils and POSIX-compliant, making it portable across Unix-like systems. It's useful for debugging, testing programs under different conditions, or in scripts requiring isolated environments.
CAVEATS
A lone - or -- implies -i; some shells may interpret -- differently. Avoid untrusted input for NAME=VALUE to prevent security issues like PATH hijacking.
EXAMPLES
env - Print all env vars.
env -i ls - Run ls in empty env.
env PATH=/bin command - Override PATH.
env -u HOME myprog - Unset HOME for myprog.
HISTORY
Specified in POSIX.1-2001; part of GNU coreutils since version 4.5.3 (1998). Widely used for portable environment manipulation.


