printenv - macOS
Overview
printenv is a macOS command that displays all environment variables and their values. It provides a convenient way to examine the current environment settings and identify any potential issues.
Syntax
printenv [parameter]...
Options/Flags
| Option | Description |
|—|—|
| -0
| Print each variable on a separate line with a null-terminated string. Useful for processing with scripts. |
| -a
| Print the environment variables used in the calling shell. |
| -i
| Print the environment variables set with inherited shells. |
| -n
| Print the environment variables set with the current shell. |
| -r
| Print the environment variables that are read-only. |
| -u
| Print the environment variables that are unset. |
Examples
-
List all environment variables:
printenv
-
Print the value of a specific variable:
printenv PATH
-
Print environment variables for use in a script:
printenv -0 | while read line; do export $line; done
Common Issues
- Uninitialized variables: If a variable is not set, it will be printed as an empty string.
- Duplicate variables: If multiple variables have the same name, only the last one is displayed.
Integration
- Shell scripts: Use
printenv
to access environment variables within shell scripts. - Debug: Use
printenv -i
to identify the environment variables inherited by a shell script.
Related Commands
- env: Prints the environment of a program.
- set: Sets environment variables.