env Command in Linux/Unix
env command is used to display and manipulate environment variables in a Unix or Linux shell. It can be employed to list existing environment variables, set new ones, or run a command with a modified environment.
env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]
env command is executed without options, it prints the current environment variables along with their values.
This command will display the current environment variables and their values.
envcommand can be used with various options to modify the behavior:
--ignore-environment: Start with an empty environment.
$ env -i
--unset=NAME: Remove variable from the environment.
$ env -u MY_VARIABLE
--null: Delimit items with null bytes.
$ env -0
Example with Options
$ env -i HOME=/newhome USER=myuser /bin/bash
This command starts a new shell with a modified environment where the
HOME the variable is set to
/newhome and the
USER the variable is set to
Purpose and Usage
The primary purpose of the
env command is to provide a clean and controlled environment for executing commands.
It is often used in scripts or shell commands to ensure a specific environment for a particular task.
env the command can be useful when you want to run a command with a modified environment without permanently changing the shell environment.