Unix / Linux Print Environment Variables Command

I am a new shell user. How do I print or list environment variables on Linux and Unix-like operating system using shell prompt? In Linux and Unix, how can I print values of all my environment variables?

You can use shell variables to store data and configuration options. You have system and user defined shell variable. One can print them as per shell name/version. This page shows how to read and set environmental and shell variables on a Linux or Unix-like systems.

Unix / Linux Print Environment Variables Command

Use the following command to display and print your environment variables at the shell prompt:

Tutorial details
Difficulty level Easy
Root privileges No
Requirements None
Est. reading time 1m
  1. Sh, Ksh, or Bash shell user type the set command.
  2. Csh or Tcsh user type the printenv command.

How the environment variables defined

The syntax is as follows on a bash/sh/ksh:

var="this is a test"  # you must use quotations when you have white space

If you are using tcsh/csh shell, try:

set var=value
set var="this is a test"
set ver=4.18.5
set dest="/backups"

Now you know how to setup the environment for your shell. Let us see how to display the value of environment variable.

Print environment variables on sh/ksh/bash Linux & Unix shell

Open the Terminal and type the following command:
$ set
$ set | more
$ set | grep 'USER'
Sample outputs:

Fig. 01: Bash/SH/KSH: set Command Display Environment Variables and Functions

Print environment variables on csh/tcsh Linux & Unix shell

Open the Terminal and type the following command:
$ printenv
$ printenv | more
$ printenv | grep 'USER'
Sample outputs:

Fig.02: CSH/TCSH shell: printenv Command Display Environment Variables

Tip: Print value of an individual shell variable

To print value of HOME variable use echo command or printf command as follows:

echo "$HOME"
echo "$var"


printf "%s\n" "$HOME"


printf "Hi, %s! You are using %s shell\n" "$USER" "$SHELL"

Sample outputs from bash shell on OS X Unix based system:

Hi, vivek! You are using /bin/bash shell

See bash(1) shell Linux/Unix man page for more information.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • aref ghobadi Aug 16, 2015 @ 15:28

    and also env command print the global vriable

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum