Skip to content

env

Cross-platform environment variable management.

Synopsis

tofu env [flags] [command]

Description

List, get, set, or filter environment variables. Works consistently across Windows, macOS, and Linux.

Flags

Flag Short Description Default
--format -f Output format: plain, json, shell, powershell plain
--filter Filter variables by prefix (case-insensitive)
--sort -s Sort variables alphabetically true
--keys -k Show only variable names false
--values -v Show only variable values false
--get -g Get a specific environment variable
--set Set variable (KEY=VALUE) and run command
--unset -u Unset variable and run command
--export -e Output in export format for shell sourcing false
--no-empty Hide variables with empty values false

Examples

List all environment variables:

tofu env

Get a specific variable:

tofu env -g PATH

Filter by prefix:

tofu env --filter HOME

JSON output:

tofu env -f json

Shell export format:

tofu env -e
# Or explicitly:
tofu env -f shell

PowerShell format:

tofu env -f powershell

Set variable and run command:

tofu env --set "NODE_ENV=production" npm start

Unset variable and run command:

tofu env -u DEBUG npm start

Show only keys:

tofu env -k

Hide empty values:

tofu env --no-empty

Sample Output

Plain format:

HOME=/home/user
PATH=/usr/bin:/bin
USER=johndoe

JSON format:

{
  "HOME": "/home/user",
  "PATH": "/usr/bin:/bin",
  "USER": "johndoe"
}

Shell export format:

export HOME='/home/user'
export PATH='/usr/bin:/bin'
export USER='johndoe'