printenv 1 user commands nosh
printenv print the whole environment, or the values of specific environment varables
`printenv` --print0 --envdir --conf --full var

## Note

C-shells have a built-in `printenv` command that has no options. See the manual for each individual shell for its built-in command.

## Description

`printenv` either prints to standard output the entire environment, or the specific environment variable(s) var. If there is no environment variable by the name of any particular var in the environment, that argument is ignored.

An environment variable that does not exist is distinct from an environment variable that does exist but that simply has an empty string for its value.

If printing the entire environment, both the environment variable names and values are printed, separated by an equals sign. If printing specific environment variables, normally only the values are printed; unless the --full option is specified to have the environment names printed in this case as well.

A process's environment variables are NUL-terminated, and may contain any other character in their names and values. If the --print0 option is specified, this is exactly how they are printed out, as NUL-terminated records. This form of output is suitable for input to utilities such as xargs 1 with its -0 option.

If the --envdir option is specified (but the --print0 option is not), the output is the same as the --print0 output except that NUL and LF characters are interchanged. Each environment variable (name and value) is always a single LF-terminated line, with interior NULs representing any LFs in the name and value. This form of output is suitable for utilities such as envdir 1 to read from a file.

If the --conf option is specified (but the --print0 and --envdir options are not), the output is converted into a quoted and escaped form. Environment variable names and values that contain anything other than `/` and characters in the POSIX Portable Filename Character Set (i.e. anything other than alphanumeric characters and the characters `/`, `-`, `_`, and `.`) are quoted, using quotation marks and backslashes to escape any quotation marks and other special characters, and the output is LF-terminated. An environment variable (name and value) may potentially be more than a single LF-terminated line. This form of output (for which one will usually use the --full option as well, to have the output in the form of a POSIX shell variable assignment) is suitable for utilities such as read-conf 1 to read from a file, or a POSIX-conformant shell interpreter to read as shell language input. It can be used to add settings to files like `/etc/rc.conf` (and its relatives), `/etc/locale.conf`, and `/etc/os-version`.

Normally however, without any of these output options in effect, the names and values of environment variables are printed as-is, and the output is LF-terminated. This form of output is ambiguous when environment variable names or values contain LF characters, with a single environment variable potentially not always being one LF-terminated line of output. It is suitable for utilities such as a POSIX-conformant shell interpreter to employ in command substitution or to read via `read` -r; but in general the other forms are the machine-parseable ones, and this form is for human beings rather than machines.

## See also

- appendpath 1

- prependpath 1

- setenv 1

- unsetenv 1

- read-conf 1

- envdir 1

## Author

Jonathan de Boyne Pollard