| .gitignore | ||
| go.mod | ||
| LICENSE | ||
| main.go | ||
| README.md | ||
envdir
A Go clone of the daemontools envdir
program.
Install
go install sneak.berlin/go/envdir@latest
Usage
envdir dir child [args...]
envdir sets various environment variables as specified by files in dir,
then runs child with the given arguments.
If dir contains a file named FOO whose first line is bar, envdir
sets the environment variable FOO to bar, then runs child.
Rules
- Each file in
dircorresponds to one environment variable. The filename is the variable name and the first line of the file is the value. - If a file is empty, the corresponding variable is unset.
- NUL bytes (
\0) in file contents are replaced with newlines. - Trailing spaces and tabs are stripped from the value.
- Lines after the first newline are ignored.
- Subdirectories and files with
=in the name are skipped. - Exit code is 111 if
envdirencounters an error.
Example
$ mkdir /tmp/env
$ echo -n "production" > /tmp/env/APP_ENV
$ echo -n "localhost:5432" > /tmp/env/DB_HOST
$ envdir /tmp/env printenv APP_ENV
production
License
MIT