printenv Command

The printenv command is used to print the values of specified environment variables, or all environment variables if none are specified. It's a simple yet powerful tool for inspecting the shell environment.

Syntax

printenv [VARIABLE_NAME]...

Description

Environment variables are dynamic-named values that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs. The printenv command provides a way to view these variables.

Common uses include:

  • Displaying all current environment variables.
  • Checking the value of a specific environment variable (e.g., PATH, HOME).
  • Debugging shell scripts by examining the environment.

Common Options

Option Description
(none) Prints all environment variables and their values.
VARIABLE_NAME Prints the value of the specified environment variable.

Examples

Print all environment variables

printenv

Displays a list of all environment variables and their corresponding values.

Print the value of a specific variable

printenv PATH

Displays the value of the PATH environment variable.

Print the value of HOME and USER variables

printenv HOME USER

Displays the values of the HOME and USER environment variables.

See also