How to see and set your environment variables
Print all your current environment variables with
$ printenv
See a the value for a specific variable with echo
$ printenv <YOUR_VARIABLE>
or $ echo $<YOUR_VARIABLE>
For example:
$ printenv MY_API_KEY
or $ echo $MY_API_KEY
How do I set the variable temporarily?
This will set your variable for ONLY your current shell session
$ export <YOUR_VARIABLE>=some-secret-pattern
You can also prepend values to a currently set variable
$ export <YOUR_VARIABLE>=some-secret-pattern:$<YOUR_VARIABLE>
This is why you see export PATH
statements like this
export PATH=/usr/local/mysql/bin:$PATH
This is actually prepending /usr/local/mysql/bin
to the existing PATH
How do I set the variable permanently?
You can run the same start up export
command with every shell session if you put this in your .bash_profile
export <YOUR_VARIABLE>=some-secret-pattern
* Make sure you source your bash_profile to see the changes
$ source ~/.bash_profile
How do I see it in my code?
Using your node shell:
node> console.log(process.env)
Using your python shell
python> import os; print os.environ