Knowledge for the World

How to print environment variables in Linux/Unix

I'll spoil it - "printenv" is your friend. This guide will show a few examples of how to use it.

1

printenv

This will print something like this:

... rvm_bin_path=/Users/josephtyler/.rvm/bin VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh VIRTUALENVWRAPPER_PROJECT_FILENAME=.project TERM_PROGRAM=Apple_Terminal GEM_HOME=/Users/josephtyler/.rvm/gems/ruby-2.2.0 SHELL=/bin/bash ...

This is a list of environment variable keys and values. There is one key/value pair per line.

2

Still using printenv if you specify a name, then the value is printed (supposing it exists).

printenv RUBY_VERSION

will simply print:

ruby-2.2.0