env command tutorial in linux/unix with examples and use cases
February 7, 2020
linux env command – run a program in a modified environment
The env command executes another program after modifying the environment as specified on the command line. When the env command is used without parameters, it prints a list of current environment variables.
Syntax
env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]
Options
- -i, –ignore-environment
start with an empty environment - -0, –null
end each output line with NUL, not newline - -u, –unset=NAME
remove variable from the environment - -C, –chdir=DIR
change working directory to DIR - -S, –split-string=S
process and split S into separate arguments; used to pass multiple arguments on shebang lines - -v, –debug
print verbose information for each processing step
Examples
Print a list of the current environment variables
➜ ~ env

Removes the specified variable from the current environment
➜ ~ env -u MAIL

Use the env command to temporarily change the environment
➜ ~ env SHELL=/bin/bash
Used to pass multiple arguments on shebang lines
Running a script named script.pl containing the following first line:
#!/usr/bin/env -S perl -w -T
Will execute perl -w -T script.pl .