Skip to main content

Overview

The env command displays all environment variables currently set in the Nash shell session. Each variable is printed in KEY=VALUE format, one per line.

Syntax

env

Description

The env command takes no arguments and lists all environment variables in the current shell context. This includes:
  • Default Nash environment variables (USER, HOME, PATH, etc.)
  • Variables set with export
  • Variables passed via -E flag at Nash startup
  • Variables inherited from parent environment

Options

The Nash env command does not accept any options or arguments. It always displays all environment variables.

Examples

Display All Variables

env
# Output:
# USER=user
# LOGNAME=user
# HOME=/home/user
# SHELL=nash
# TERM=xterm-256color
# LANG=en_US.UTF-8
# LC_ALL=en_US.UTF-8
# PATH=/usr/local/bin:/usr/bin:/bin
# PWD=/home/user
# HOSTNAME=nash
# SHLVL=1

Filter Specific Variables

env | grep PATH
# Output: PATH=/usr/local/bin:/usr/bin:/bin

Count Variables

env | wc -l
# Output: 11

Search for Variable Pattern

env | grep -i lang
# Output:
# LANG=en_US.UTF-8
# LC_ALL=en_US.UTF-8

Sort Variables Alphabetically

env | sort

Practical Use Cases

Debug Environment Issues

# Check if required variable is set
env | grep API_KEY

Export Environment Snapshot

# Save current environment to file
env > environment-backup.txt

Compare Environments

# Before making changes
env | sort > env-before.txt

# After making changes
env | sort > env-after.txt

# View differences
grep -v -f env-before.txt env-after.txt

Verify Path Configuration

# Extract and display PATH
env | grep PATH | cut -d= -f2
# Output: /usr/local/bin:/usr/bin:/bin

Check User Context

# View user-related variables
env | grep -E "USER|HOME|SHELL"
# Output:
# USER=user
# HOME=/home/user
# SHELL=nash

Default Environment Variables

Nash sets these standard Unix environment variables by default:
USER
string
Current username (set via -U flag or defaults to user)
LOGNAME
string
Same as USER - login name
HOME
string
User’s home directory (/home/<username>)
SHELL
string
Current shell (nash)
TERM
string
Terminal type (xterm-256color)
LANG
string
System language (en_US.UTF-8)
LC_ALL
string
Locale setting (en_US.UTF-8)
PATH
string
Executable search path (/usr/local/bin:/usr/bin:/bin)
PWD
string
Current working directory (updated by cd)
OLDPWD
string
Previous working directory (used by cd -)
HOSTNAME
string
System hostname (nash)
SHLVL
string
Shell nesting level (starts at 1)

Output Format

Each environment variable is printed as:
KEY=VALUE
  • No spaces around the = sign
  • One variable per line
  • No special formatting or quoting
  • Order is not guaranteed

Notes

  • Variables with empty values are shown as KEY=
  • The output includes all variables, not just exported ones
  • Variable values may contain special characters or spaces
  • Use export to modify variables and unset to remove them

Exit Status

The env command always returns exit code 0 (success).
  • export - Set or modify environment variables
  • unset - Remove environment variables
  • echo - Display variable values with echo $VAR
  • grep - Filter environment variable output

Build docs developers (and LLMs) love