1 unstable release
| 0.1.0 | May 6, 2026 |
|---|
#583 in Filesystem
34KB
814 lines
tenenv
tenenv (Japanese 点 + env) is a dotenv CLI that loads a .env file and runs a command with those environment variables set.
tenenv [OPTIONS] [--] COMMAND [ARGS...]
Installation
Via Cargo
If you have Rust installed, install tenenv from crates.io:
cargo install tenenv
Via mise
If you use mise, install tenenv as a global tool (downloads a pre-built binary from GitHub releases):
mise use -g github:dahlia/tenenv
Binary releases
Pre-built binaries for Linux (x86_64, aarch64), macOS (x86_64, aarch64), and Windows (x86_64, aarch64) are available on the releases page.
From source
Clone the repository and build with Cargo:
cargo build --release
The binary is placed at target/release/tenenv.
Usage
tenenv [OPTIONS] [--] COMMAND [ARGS...]
Options:
| Option | Default | Description |
|---|---|---|
-f FILE, --file FILE |
.env | Path to the env file |
--strict |
Exit non-zero if the env file is not found | |
-o, --override |
Override existing environment variables |
Without --strict, a missing env file produces a warning on stderr and
the command runs with the unmodified environment.
Without --override, variables already set in the environment take
priority over definitions in the env file. When the same key appears
more than once in the file, the last definition wins.
On Unix, tenenv replaces its own process image with the command
(execvp), so the command appears directly in the process list and
inherits signals properly. On other platforms, tenenv spawns a child
process and waits for it to finish.
Exit status: tenenv exits with the same code as the command. If the command is not found, it exits 127; if the command is found but not executable (Unix only), it exits 126.
Examples
Run a server with production settings:
tenenv -f .env.production -- node server.js
Override an already-set variable for a single invocation:
tenenv --override -- cargo test
Use a strict mode to catch a missing env file in CI:
tenenv --strict -f /etc/app/.env -- ./start.sh
Env file format
tenenv supports a subset of POSIX shell variable assignment syntax.
Basic assignments
Variable names must start with an ASCII letter or underscore, followed by ASCII letters, digits, or underscores.
HOST=localhost
PORT=5432
_PRIVATE=value
Bare (unquoted) values may not contain spaces, tabs, or other whitespace.
Use quoting for values that contain whitespace or shell metacharacters.
NUL bytes (\0) in values are a parse error.
Comments
Lines starting with # are comments. An inline comment can follow a
value if it is preceded by whitespace:
HOST=localhost # this is a comment
PORT=5432#this is NOT a comment; the hash is part of the value
The export keyword
The export prefix is accepted and ignored (all loaded variables are
exported to the child process):
export HOST=localhost
Quoting
Single quotes preserve the literal value of every character inside them. No escape sequences are processed:
MSG='hello $USER' # value is: hello $USER
Double quotes support escape sequences and variable expansion. The
recognised escape sequences are \", \\, \$, and \`. A
backslash at the end of a line inside double quotes continues the string
on the next physical line (the backslash and newline are removed):
GREETING="hello \"world\""
MULTILINE="first line\
second line"
Any other \X sequence inside double quotes is a parse error.
Variable expansion
Inside double-quoted values, $VAR and ${VAR} are expanded.
Variables defined earlier in the same file take priority over the current
environment. If a variable is not defined anywhere, it expands to an empty
string:
BASE=/opt/app
DATA="${BASE}/data" # expands to /opt/app/data
MISSING="${UNDEFINED}x" # expands to x
A bare $ not followed by a letter or underscore is treated literally:
PRICE="$100" # value is: $100
License
Copyright (C) Hong Minhee and contributors.
tenenv is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
See the LICENSE file for the full license text.
Dependencies
~0.8–1.4MB
~25K SLoC