envdir 1 user commands nosh
envdir set environment variables then chain
`envdir` --ignore-nodir --full --chomp dir next-prog

## Description

`envdir` is a chain-loading utility that sets and unsets environment variables according to the files in dir and then chain loads to next-prog with the execvp 3 function.

next-prog may contain its own command line options, which `envdir` will ignore.

Unless the --ignore-nodir command line option is used, the non-existence of dir, or it being something other than a directory, is a fatal error.

For each file `file` in dir:

- If the file is empty, `envdir` unsets the variable `file` if it is set.

- Otherwise `envdir` sets the variable `file`, overwriting its existing value if it has one, to the contents of `file`, after turning NUL characters into LF characters (and turning the final LF character into a string-terminating NUL).

  If the --full command line option is used, `envdir` uses the full contents of `file`; otherwise it uses just the first line of those contents. This is a bodge for malformed out-of-spec environment directories. Always create environment directories properly, according to the Bernstein specification, and you should never need this. Use tr 1 in shell scripts to properly translate LFs to NULs for writing environment directories, for example.

  If the --chomp command line option is used, each line used has leading and trailing whitespace characters trimmed.

`envdir` skips directory entries that aren't regular files (or symbolic links to regular files), trying not to even attempt to open them if the operating system's directory scanning ability includes the reporting of entry types. It also skips entries whose names begin with a dot.

`envdir` makes no attempt to sanitize the contents of `file` or the name `file`. If the name or the contents contain an `=` character, counter-intuitive things will happen to the environment. If the contents have whitespace at the end of the first line, that will be included in the variable's value in the environment.

## Bugs

As of version 1.34 this program no longer employs the GNU C library nor the BSD C library for environment variable handling. The previously documented workaround for those libraries' having memory leaks in their setenv 3 and clearenv 3 functions, is therefore no longer necessary.

## See also

- appendpath 1

- prependpath 1

- setenv 1

- unsetenv 1

- read-conf 1

- printenv 1

- The `set-service-env` and `print-service-env` subcommands of system-control 1

## Author

Jonathan de Boyne Pollard