Command Line part 8
Week 1 -Command line
When in the command line we are always in an environment, you terminal will know which user your operating under, your permissions and so forth. You can see the details of your environment entering “env” in terminal and “SET” in Windows. Each item on the list will have a key value pair, example “USERNAME = Steven”.
Setting environment variables
Here is an example of how to set and use an environment variable, we use the command “export”. An example of when we may wish to do this is when we want to hide sensitive info such as passwords. For example we could do the following “export SECRET_KEY=password1234” then, in our code read the value as follows “secret_key = ENV[‘SECRET_KEY’]”. This means if we were to upload the code and share it with the world this information would remain hidden. One important thing to note however is when we close the environment this environment we created will cease to exist, in order to make this a more permanent solution we will need to use rvm.
To achieve this we do the following (this will not work on windows without something such as c9io) “echo “export PASSWORD=1234” >> ~/.bash_profile” (>> means append, > means overwrite). Now when we close terminal this environment should be saved for future use.
