≡ Menu

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 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:

  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.

{ 1 comment… add one }
  • aref ghobadi August 16, 2015, 3:28 pm

    Hi,
    thanks
    and also env command print the global vriable

Leave a Comment


   Tagged with: , ,