How to Use the Env Command in Linux

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 command:

$ env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]
1. Run a process without the existing environment variables
env -i your_command

The -i or --ignore-environment option runs the command with an empty environment

Example: Type env -i /bin/sh to create a new environment without any existing environment variables.

run process without existing envrun process without existing env
2. Add an environment variable
env variable_name

Use the env variable_name command to set a new environment variable.

Example: Set a new environment variable named Example.

add env viarableadd env viarable
3. Remove an environment variable
env -u variable_name

Use the -u or --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.

remove env viarableremove env viarable
4. Remove the line break from the environment variables list
env -0

The -0 or --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.

remove line breakremove line break

The post How to Use the Env Command in Linux appeared first on Hongkiat.

from Signage https://ift.tt/hNR6aOV
via Irvine Sign Company