Unix/ Linux: Print Environment Variables Command

by on February 4, 2013 · 0 comments· LAST UPDATED February 4, 2014

in , , ,

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 Linix and Unix, how can I print values of all my environment variables?

As per your shell name (version) use the following command to display and print your environment variables at the shell prompt:
Tutorial details
DifficultyEasy (rss)
Root privilegesNo
RequirementsNone
Estimated completion time1m

  1. Sh, Ksh, or Bash shell user type set command.
  2. Csh or Tcsh user type printenv command.

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

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

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

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
OR
$ printenv | more
OR
$ printenv | grep 'USER'
Sample outputs:

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

Fig.01: 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"

OR

printf "%s\n" "$HOME"

OR

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

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

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

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

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Tagged as: , ,

Previous Faq:

Next Faq: