from dotenv for formats
Command Type
built-in
Signature
> from dotenv {flags}
Input/output types:
| input | output |
|---|---|
| string | record |
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 .envLoad a .env file into the environment.
> open .env | load-envNotes
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.