An environment variable is a value available in your computer globally, which may contain anything from the path to the root directory, the home directory, and a secret token.
This command can reveal the list of these environment variables. It can also be used to add, update and remove a variable.
General syntax for
$ env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]
1. Run a process without the existing environment variables
env -i your_command
--ignore-environment option runs the command with an empty environment
env -i /bin/sh to create a new environment without any existing environment variables.
2. Add an environment variable
env variable_name command to set a new environment variable.
Example: Set a new environment variable named Example.
3. Remove an environment variable
env -u variable_name
--unset option to remove the variable from the environment.
Example: Removing the Example environment variable. As you can see in the screenshot, the variable we recently created no longer exists.
4. Remove the line break from the environment variables list
--null option ends each line of output with a 0 (null) byte, not a newline.
Example: Using the
env command to separate output lines with the NULL character.