Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Shells
    • Strings
    • System
    • Viewers

from dotenv for formats

Parse text as a .env file and create a record.

Command Type

built-in

Signature

> from dotenv {flags}

Input/output types:

inputoutput
stringrecord

Examples

Read a .env file into a record.

> "PORT=8080
export NAME='my app'
# a comment
GREETING=\"hello ${NAME}\"" | from dotenv
╭──────────┬──────────────╮
│ PORT     │ 8080         │
│ NAME     │ my app       │
│ GREETING │ hello my app │
╰──────────┴──────────────╯

Use a default for a variable that isn't set.

> "URL=http://${APP_HOST:-localhost}:8080" | from dotenv
╭─────┬───────────────────────╮
│ URL │ http://localhost:8080 │
╰─────┴───────────────────────╯

Read a .env file from disk.

> open .env

Load a .env file into the environment.

> open .env | load-env

Notes

Each line is KEY=value, optionally starting with export. Values can be unquoted, single-quoted or double-quoted, and quoted values can span lines. In unquoted and double-quoted values, ${NAME} and $NAME expand to an earlier key of the file, or else to the environment variable; names ignore case, as in $env, so a=2 after A=1 sets A again. A bare $NAME is letters, digits and _, so $HOST.local reads HOST, and a $ before anything else, as in $5 or $(command), stays as written: commands aren't run. Single quotes or \$ keep a $. As in sh, ${NAME:-word} gives word when NAME is unset or empty and ${NAME-word} only when it's unset, while ${NAME:+word} gives word when NAME is set and not empty and ${NAME+word} when it's set at all, so a key holding - can't be referenced: ${MY-VAR} gives MY, or VAR when it's unset. A line starting with # is a comment, and so is a # after a blank in an unquoted value. open reads files named like .env, .env.local or prod.env with this command, and load-env loads the record into the environment.