0

I accidentally overwrote my .profile file and I believe deleted my environment variables. To be honest, I don't really understand how the operating system handles environment variables. My rough understanding is that there are configuration files like .profile which the operating system looks at, or runs, automatically and sets the environment variables that way. But how does the system know which config files to run? Are there default config files? Is .profile a default config file in OS X? If .profile is one of these default config files, is there a way for me to retrieve it or else the environment variables that it sets by default. What are the default values for .profile in OS X?

migrated from stackoverflow.com Apr 12 '16 at 15:21

This question came from our site for professional and enthusiast programmers.

  • .profile is not a Bash file, exclusively. It is read by sh and possibly other shells as well. – tripleee Apr 7 '16 at 5:29
  • Most of environment variables are not set by .profile. By default, that file does not even exist. Whatever problem you have, it is not because you have overwritten your .profile. – hamstergene Apr 9 '16 at 20:33
1

In your terminal that still has the variables write printenv > with_profile.txt. This will dump all available variables into with_profile.txt. Open a new terminal window and write printenv > without_profile.txt.

Start python and write:

with open("with_profile.txt") as w_profile, open("without_profile.txt") as wo_profile: 
    w_profile_vars = {line.strip() for line in w_profile}
    wo_profile_vars = {line.strip() for line in wo_profile}
    for var in w_profile_vars - wo_profile_vars: 
        print var

That should print the set of missing variables one by one.

P.S.

~/.profile is not there by default (not on Mavericks, Yosemite and El Capitan for sure). Hence it's possible that you overwrote nothing, unless you had created the file yourself a long ago.

You must log in to answer this question.