@karmaniverous/get-dotenv
    Preparing search index...

    This page documents the root shell behavior controlled by the host’s global --shell (and optional root scripts). Plugins normally rely on the root shell setting; a rare per‑script override may be honored by CLI‑driven plugins when a script entry uses the object form { cmd, shell }. For subprocess patterns across plugins (including expansion timing, child env composition, capture, quoting, and safety), see Authoring Plugins → Executing Shell Commands.

    Shell execution behavior

    get-dotenv executes commands via execa and normalizes shell behavior across platforms.

    • --shell (or shell: true): use a normalized default shell. shell: true means this shell wherever it is set: the root, a script entry, plugin config, or a direct runCommand(..., true).
      • POSIX: /bin/bash
      • Windows: powershell.exe
    • --shell <string>: use the provided shell (e.g., /bin/zsh)
    • --shell-off (or shell: false): execute without a shell (plain execa)
    • Scripts table overrides: when a script entry uses the object form { cmd, shell }, the effective shell is scripts[name].shell (and when omitted, the script currently runs with shell OFF rather than inheriting the root shell).
    • Plain (no shell): safer for simple commands; pipes, redirects, and globbing are not available unless the command itself implements them. When get-dotenv is given a string command in shell-off mode, it tokenizes it using a minimal tokenizer; for complex quoting or node -e/--eval payloads, prefer passing argv tokens (or use the cmd/batch positional token forms) so payloads are preserved precisely.
    • Shell mode: the specified shell parses the command string, enabling pipes, redirects, aliases, and shell builtins. The string reaches the shell exactly as given (runs of spaces and \ escapes included). Quoting and escaping must follow the shell's rules.

    Use the default shell:

    getdotenv cmd echo OK
    

    Disable shell parsing entirely:

    getdotenv --shell-off cmd node -e "console.log('hello')"
    

    Force a specific shell:

    getdotenv --shell /bin/zsh cmd 'echo "quoted with zsh"'
    

    Script-level shell override (example getdotenv.config.json):

    {
    "scripts": {
    "bash-only": { "cmd": "echo $SHELL && echo OK", "shell": "/bin/bash" },
    "plain": { "cmd": "node -v", "shell": false }
    }
    }

    Then:

    getdotenv cmd bash-only
    getdotenv cmd plain

    TypeScript note: When you author scripts in code, a helper defineScripts<TShell>()(table) is available to preserve concrete shell types through helpers and overrides. This keeps script‑level shell choices strongly typed where you need them.

    • POSIX shells: prefer single quotes when possible; escape $ for literal dollar signs.
    • PowerShell: double-quotes perform interpolation; single quotes are literal.
    • Argv forms (batch positionals, the aws forward) are joined into one string for the shell with each token quoted by that shell's own rules: single quotes for POSIX shells and PowerShell, caret-escaped double quotes for cmd.exe. A PowerShell command name that needs quotes runs through the call operator (& '...'). An empty argument is kept ('', or "" for cmd.exe).
    • PowerShell argv tokens (powershell.exe, and pwsh 7.3 or later with its default $PSNativeCommandArgumentPassing): every token is single-quoted, so PowerShell reads nothing in it. Each character PowerShell treats as a single quote (' and the curly quotes U+2018 to U+201B) is doubled. A token that is exactly --% is passed as @('--%'), because PowerShell takes any argument whose value is --%, quoted or not, as its stop-parsing marker. Under pwsh's default Windows mode, arguments to cmd.exe and batch files use PowerShell's legacy passing, which these rules don't cover.
    • Shell off, the same argv array can reach the child differently. Each argument (not the command name) loses matching outer quotes, repeatedly ('"quoted words"' and """code""" both arrive as the bare text), because no shell is there to remove the quotes a user typed (spec section 4: shell off strips symmetric outer quotes from argv arrays; 7.x did the same). With a shell, each token is quoted as given, so the quotes reach the child: ['node', 'x.js', '"a b"'] passes "a b" with a shell and a b without one.
    • cmd.exe argv tokens: each token is first escaped for the program's argv parser (the MSVCRT / CommandLineToArgvW rules: wrapped in ", an embedded " as \", backslashes doubled before a " and at the end), then every cmd.exe metacharacter, quotes included, gets a ^, as cross-spawn does (after qntm.org/cmd). %VAR% and !VAR! arrive literally. cmd.exe can't stop a %name:old=new% or %name:~n,m% edit, or carry a line break, so a token list that would need either throws an error naming the problem (never the token): run it with shell: false or another shell. A command name with spaces goes in plain quotes; one holding " or % throws. Not covered: a variable whose name contains ^, !VAR! when delayed expansion is turned on in the registry (it is off by default), and a batch file (npm.cmd and the like), which parses its arguments a second time.

    get-dotenv exits with the child's exit code on every execution path (cmd, the default command, the -c alias, the aws forward, batch) and exits non-zero on usage errors. A child that can't be started (e.g. ENOENT with the shell off) prints Error: <message> and exits 127 (ENOENT) or 1. On Windows, execa runs a command name it can't resolve through cmd.exe (cross-spawn), which prints its own "is not recognized" message and exits 1. Under the default Windows shell, powershell.exe -Command reports any failure as 1, so the original code is lost there.

    Nested getdotenv invocations inherit parent CLI options and the loaded dotenv context via process.env.getDotenvCliOptions (JSON). The shell resolution and scripts table continue to apply within nested commands using the same rules. The parent's options rank above the child's own defaults and config, so a parent run with --shell-off (shell: false) runs the child without a shell too, even when the child's own default shell is a string; the child's own --shell still wins.

    Child processes receive a normalized environment composed from the parent and the current dotenv context:

    • Composition: { ...process.env, ...ctx.dotenv }
    • Normalization: a single helper drops undefined values and improves cross-platform behavior (e.g., TMP/TEMP coherence and HOME fallback on Windows; TMPDIR population on POSIX).
    • This keeps subprocess behavior consistent across platforms and surfaces.

    By default, child process output is streamed live (stdio: 'inherit'). For deterministic logs in CI or tests, enable capture:

    • Flag: --capture
    • Env: GETDOTENV_STDIO=pipe

    When capture is enabled, commands run with stdio: 'pipe' and the host re-emits the child's buffered stdout to stdout and its stderr to stderr after the child completes. Live streaming remains available by omitting the flag/env (the default).

    Root and plugin flags display effective defaults derived from the same resolved configuration (overlays + dynamic), evaluated safely at help time:

    • Top‑level -h/--help computes a read‑only resolved config and evaluates dynamic descriptions (no logging; no process.env mutation).
    • Subcommand help is rendered with getdotenv <cmd> -h / --help. Only top-level -h/--help is guaranteed to run with side effects suppressed.
    • Every help shows each option's qualified name ((anywhere: --getdotenv-env)), and a subcommand's help lists the options of the commands above it by qualified name. See Qualified options.

    Examples (concise excerpts):

    # getdotenv -h (on Linux; on Windows the default shell is powershell.exe)
      -p, --load-process        load variables to process.env ON (default) (anywhere: --getdotenv-load-process)
      -P, --load-process-off    load variables to process.env OFF (anywhere: --getdotenv-load-process-off)
      -L, --log-off             console log loaded variables OFF (default) (anywhere: --getdotenv-log-off)
      -s, --shell [string]      command execution shell, no argument for default OS shell or provide shell string (default /bin/bash) (anywhere: --getdotenv-shell)
    
    # getdotenv batch -h
      -g, --globs <string>      space-delimited globs from root path (default: "*") (anywhere: --getdotenv-batch-globs)
      -r, --root-path <string>  path to batch root directory from current working directory (default: "./") (anywhere: --getdotenv-batch-root-path)
    

    Notes:

    • For plugin defaults, set values under plugins.<mount-path> in your config (for example plugins.aws/whoami), and prefer plugin.createPluginDynamicOption(cli, …) so the callback receives the validated, instance-bound plugin config slice.
    • Use ON/OFF labels (“(default)”) for boolean toggles and “(default: "...")” for string defaults to keep output concise and consistent.

    TypeScript note: Many helper APIs (e.g., env overlay/expansion utilities) accept readonly record inputs, so as const maps are fine to pass where appropriate.