How to print environment variables in Linux/Unix

Tyler Tyler (258)
0

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

Posted in these interests:

webdev
PRIMARY
83 subscribers
linux
75 subscribers
unix
18 subscribers
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.

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