env
run programs with modified environment variables
TLDR
Show all environment variables
SYNOPSIS
env [options] [VAR=value]... [command]
DESCRIPTION
env runs a program in a modified environment. It can display current environment variables, set new ones, unset existing ones, or run commands with a clean environment.
The command is useful for setting variables temporarily or debugging environment issues.
PARAMETERS
-i, --ignore-environment
Start with empty environment-u var, --unset=var
Remove variable from environment-0, --null
End lines with NUL, not newline-C dir, --chdir=dir
Change directory before running command-S string
Process and split string into arguments
WORKFLOW
env
# Set variable for one command
env DEBUG=1 ./program
# Multiple variables
env VAR1=value1 VAR2=value2 command
# Clear environment
env -i command
# Clean environment with specific variables
env -i PATH=/usr/bin HOME=/home/user command
# Unset variable
env -u DISPLAY command
# Change directory first
env -C /tmp ls
# In shebang for portability
#!/usr/bin/env python3
COMMON USES
Shebang lines:
#!/usr/bin/env python3
#!/usr/bin/env node
env DATABASE_URL=postgres://... rails console
env | sort
VARIABLE FORMAT
Variables shown as:
PATH=/usr/bin:/bin
HOME=/home/user
COMPARISON WITH EXPORT
env
Runs command with modified environmentexport
Sets variables for current shell and children
env VAR=value command
# export (persistent)
export VAR=value
command # VAR is available
CAVEATS
Variables set with env don't persist after command exits. Shell built-ins may not be accessible with env. PATH must be set for clean environment. Quotes needed for values with spaces. Different from the export shell built-in.
HISTORY
env has been part of Unix since the early days, included in POSIX standards for environment manipulation.
