Skip to content
Related Articles

Related Articles

env command in Linux with Examples
  • Last Updated : 15 May, 2019

env is used to either print environment variables. It is also used to run a utility or command in a custom environment. In practice, env has another common use. It is often used by shell scripts to launch the correct interpreter. In this usage, the environment is typically not changed.

Syntax :

env [OPTION]... [-][NAME=VALUE]... [COMMAND [ARG]...]

Options of env command

1. Without any argument : print out a list of all environment variables.

EXAMPLE :



env

2. -i or –ignore-environment or only – : runs a command with an empty environment

SYNTAX :

$ env -i your_command

Note: This completely clear out the environment, but it does not prevent your_command setting new variables.

EXAMPLE : To clear the environment (creating a new environment without any existing environment variables) for a new shell

env_1

In this, it clears all the environment variable and then new shell sets the environment variable PWD. Thus in this new shell when we execute env, we only see one environment variable PWD.

3. -u or –unset: remove variable from the environment



SYNTAX :

$ env -u variable_name

EXAMPLE : Removing XDG_VTNR environment variable which you can see in the image above in the output of just env.

env_2

4. -0 or –null: End each output line with NULL, not newline

SYNTAX :

$ env -0

EXAMPLE :

env_5

5. –version: Display version information and exit.

SYNTAX :

$ env --version

EXAMPLE :

env_3

6. –help: Display a help message and exit.

SYNTAX :

$ env --help

EXAMPLE :

env_4

My Personal Notes arrow_drop_up
Recommended Articles
Page :