A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/linux-unix/env-command-in-linux-with-examples/ below:

env command in Linux with Examples

env command in Linux with Examples

Last Updated : 03 Sep, 2024

The 'env' command in Linux is a versatile tool used to manage environment variables. It can print all the current environment variables, set new ones, or run a command within a custom environment. Additionally, 'env' is commonly used in shell scripts to launch the correct interpreter, ensuring the script runs with the intended environment settings.

Here, we will learn more about 'env' command in Linux along with some practical examples.

What Does the env Command Do?

The primary function of the 'env' command is to display environment variables or run commands within a modified environment. Environment variables are dynamic values that affect the processes or programs running on a system, such as 'PATH', 'HOME', and 'USER'. By using 'env', you can manipulate these variables to customize the behavior of your commands and scripts.

Syntax:
env [OPTION]... [-][NAME=VALUE]... [COMMAND [ARG]...]
Options of the 'env' command

Here are some common ways to use the 'env' command along with practical examples:

1. Without any argument

Print out a list of all environment variables.

EXAMPLE:

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

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'.

4. '-0' or '--null'

End each output line with NULL, not newline

SYNTAX:

$ env -0

EXAMPLE:

5. '--version'

Display version information and exit.

SYNTAX:

$ env --version

EXAMPLE:

6. '--help'

Display a help message and exit.

SYNTAX:

$ env --help

EXAMPLE:

Conclusion

The 'env' command in Linux is an essential tool for managing environment variables and controlling the behavior of commands and scripts. Mastering 'env' can significantly enhance your efficiency and control over your Linux environment. By familiarizing yourself with its options and practical uses, you can leverage 'env' to customize your workflow and ensure your scripts and commands run as intended.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4