calthoff / tstp

This is an old repository for the exercises in "The Self-Taught Programmer." Please see /selftaught.
166 stars 193 forks source link

Chapter 16, challenge 3 #7

Closed jonathan-j-stone closed 7 years ago

jonathan-j-stone commented 7 years ago

I really did not understand this concept of creating environmental variables, so the challenge left me completely lost. I don't even understand the answer to the challenge.

Is there a resource that you can point to that discusses this topic as it seems like it could be important going forward?

VetAran commented 7 years ago

@ILeftTheLaw I am with you. I am going back to Ch 7 to ensure I have everything, I think maybe I rushed 7 through here. I could understand the bash and changing variables and the file add/remove from .profile, however the variable is what is stored in your OS, yet if you close the bash x is no more.

So was x only there because I made it (x became an env variable) then it is gone once bash is closed? Why? I can create env variables in the OS (or anywhere as far as I can tell), so what is the point of mentioning an OS variable if we do not get to tap into one that is actually hardwired into it? I was all lost.

I am taking the weekend off and going back to Ch 7. Ch 16 was the hardest chapter thus far for me.

calthoff commented 7 years ago

@ILeftTheLaw @Sir-Python-Damselrot Great question. You can make an environmental variable permanent by storing it in a special file in Bash called .profile. For example, if you want to make an environmental variable called x equal to 100, you would cd to your home directory "cd ~". Then open up your profile file "vim .profile". Next, you would put the following code into it, save, and exit "export x=100", ":x". Close the current window and open a new one. When you type "echo x" you will now see 100.

jonathan-j-stone commented 7 years ago

Thank you @calthoff .