Skip to content

Latest commit

 

History

History
151 lines (96 loc) · 3.96 KB

File metadata and controls

151 lines (96 loc) · 3.96 KB

DOTENV(1) Manual Page

NAME

dotenv - load environment variables from .env files and execute command

SYNOPSIS

dotenv [-h | --help]
dotenv [-x | --exec] [-o | --override] [-s | --strict] [-q | --quiet] [-e FILE]…​ COMMAND [ARGS…​]

DESCRIPTION

dotenv loads environment variables from one or more .env files and executes a command with the loaded environment. It supports multiline values, quoted strings, and comments.

By default, environment variables that are already set in the calling environment take precedence over variables defined in .env files. Use the -o option to reverse this behavior and have .env file values override the calling environment.

The .env file format follows common conventions. For detailed syntax information, see env(5).

OPTIONS

-e, --env-file FILE

Specify .env file to load. Can be specified multiple times to load multiple files. If not specified, defaults to .env. Files are processed in order, with later files overriding variables from earlier files.

-x, --exec

Replace the current shell process with the executed command instead of running it in a subprocess.

-o, --override

Override existing environment variables with values from .env files. By default, environment variables already set take precedence over .env values.

-s, --strict

Fail with exit code 1 when warnings occur (e.g., missing .env files, unclosed quotes).

-q, --quiet

Suppress warning messages. Does not affect error behavior.

-h, --help

Show help message and exit.

-V, --version

Show version information and exit.

ARGUMENTS

COMMAND

Command to execute with the loaded environment variables.

ARGS…​

Arguments to pass to the command.

VARIABLE PRECEDENCE

By default, variables are resolved in the following order (highest to lowest):

  1. Environment variables set in the calling shell

  2. Variables from .env files (processed in command-line order)

This means that TEST=override dotenv -e .env command will use "override" as the value of TEST, regardless of what .env contains.

When -o is specified, .env file values take precedence over the calling environment:

  1. Variables from .env files (processed in command-line order)

  2. Environment variables set in the calling shell

When multiple .env files are specified, later files always override variables from earlier files.

Note
An environment variable set to an empty string is still considered "set" and will take precedence over .env file values (unless -o is used). Use unset VAR to allow the .env value to be used.

EXAMPLES

Execute go command with environment from .env file

dotenv go run main.go

Load variables from multiple .env files and run Python script

dotenv -e .env -e .env.production python app.py

Use custom .env file with npm

dotenv -e .env.local npm start

Override .env file value with environment variable

TEST=override dotenv -e .env printenv TEST

Force .env file values to override existing environment variables

TEST=existing dotenv -o -e .env printenv TEST

Fail if .env.production is missing instead of just warning

dotenv -s -e .env.production python app.py

Suppress warning message about missing.env file

dotenv -q -e missing.env node server.js

Replace current shell with bash using environment from .env file

dotenv -x -e .env bash

Replace current process with Node.js server using default .env file

dotenv --exec node server.js

EXIT STATUS

0

Success.

1

Runtime error (file not found in strict mode, parse error).

2

Usage error (missing command, invalid options).

N

Exit status of the executed command.

FILES

.env

Default environment file if no -e option is specified.

SEE ALSO

env(5), env(1), export(1), source(1), exec(1)