Skip to content

The env command

The env command lists every environment variable as NAME=value, one per line.

A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.

Usage

env
env [-i] [-u NAME] [NAME=VALUE]... COMMAND [ARGUMENT]...

List environment variables, or run a command with changes. With no command, prints every exported variable as NAME=value. Given a command, runs it with the variables changed for that command only. A #! line often uses /usr/bin/env bash so the script finds bash wherever it is installed.

How to use env

List the environment

env
EDITOR=nano
HOME=/home/learner
LANG=en_US.UTF-8
LOGNAME=learner
OLDPWD=/home/learner/projects
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/home/learner
SHELL=/bin/bash
USER=learner

Find one variable

env | grep HOME
HOME=/home/learner
printenv USER
learner

Options

-istart with no variables at all
-u NAMEleave out one variable

More examples

env GREETING=hi printenv GREETING
Hi, for that command only
hi

Questions about env

What is the difference between env and printenv?

With no arguments they print the same list. printenv NAME prints one value; env can also run a command with changed variables.

Every everyday command on one page, to print or keep open: the Linux commands cheat sheet.