Recording problems in the environment variables at the terminal --mac

  Has been used a few years ago to buy a MacBook Air, was feeling very thin, the appearance is also very nice, but also has been used now, there are about three or four years, the system is still very smooth (to be honest, not advertising .... ..). Usually is often used mac terminal, to be honest, since the use of the terminal mac, linux command with basically the same as handy, and then use cmd in the windows felt very uncomfortable, up hit ls, windows are dir, of course, some command is the same, such as mkdir.

  Well, the other is not to say, this problem occurs mainly use this period of time the terminal mac, I found the configuration environment variable is always somehow fail, every time source, and look for source a bit further not enough, each time re-open the terminal to be re source, it is the beginning did not care, because the original has not been the problem, but usually it is not essentially shut down the computer when not directly close, so it does not care how. Appear again today this problem when he was going to have to get rid of, in the end Why?

  First online Baidu a moment when the Terminal init order to load the configuration file:

is generally used as the default mac bash the shell 

the Mac system environment variables, the load order is:
 / etc / Profile / etc / Paths ~ / .bash_profile ~ / ~ .bash_login / .profile ~ / .bashrc

  My environment variable is configured to ~ / .bash_profile file, searches are beginning to make a lot of modifications .zshrc file, just the beginning of the installation do this, then do not bash the original interface or feeling watching habits uninstall it, and I thought no clean uninstall of the problem, looking for a half-day .zshrc files have not found it first denied the problem is. Since then determine the order of the terminal to load the initial configuration file, you can locate the problem step by step, for these configuration file, / etc the following two files are system level, will be loaded when the system starts, followed by a few is the current user level. 3 later read from front to back in order, if ~ / .bash_profile file exists, the next few read file will be ignored, and if ~ / .bash_profile file does not exist, and so will read file back. ~ / .bashrc no such rule, it is loaded bash shell when opened. Here you can recommend a great God blog, these documents explain in great detail, I will not detail here: the MAC are several ways to set the environment variable path

 

  According to the above rules, it seems ~ / .bashrc is rather special, is to open the terminal will be loaded, and I was put into an environment variable configuration file .bash_profile, then here we can test it, first open it. bashrc file to look at what's inside. Enter the command: vi ~ / .bashrc, I found it was empty, then you can enter in there echo ".bashrc run", save and exit. Reopen After exiting the terminal, found no output ".bashrc run", that it is not contrary to the above rule with it? So I searched again, found the answer in another big brother article:

Mac OS X environment variable is set to [turn] - Helix log - Netease blog

"OS X and Linux are both .bash_profile and .bashrc configuration file.

However, in the case of OS X in the encounter bashrc is not in force.

When the shell is a login shell, .bash_profile will be loaded, and bashrc just the opposite.

The real difference is in the linux, when a user logs into a graphical interface, and then open a terminal Terminal, shell that is non-login shell.

However, when the OS X login, and not running a shell, so that, when run Terminal.app, in fact, it is a login shell.

You can still write some configuration in bashrc, as long as the source .bashrc bash_profile where it wants.

For the login shell, and I did find an answer to the configuration terminal: Click the terminal "Preferences" option

In a general column can be seen in the shell open with "default login Shell". At first I found that I chose "command (full path)" in this way will not be loaded ".bash_profile" file, this is my turn later found to ensure .bash_profile file in the open load.

 

 

   Select the Shell Open after "the default Login Shell", test to see whether the terminal is opened to load. First written in .bash_profile file echo ".bash_profile file to run the" save and close the terminal reopened after exiting.

 

  I found .bash_profile Now is when the terminal opened on the first reading, while just .bashrc file is not loaded in the open, so if I want to configure the environment variable to the .bashrc file, we can .bash_profile file write "source ~ / .bashrc", because the terminal is opened .bash_profile priority load, is loaded into the "source ~ / .bashrc" it will be a time to load .bashrc file, so as to ensure the configuration file .bashrc environment variables can be loaded into, you can test the following:

1 .bash_profile file written echo ".bash_profile file run" and "source ~ / .bashrc"  

2 .bashrc file written echo ".bashrc file to run"

After closing the terminal reopened:

You can clearly see, after opening the first output terminal of the ".bash_profile file to run," and then output ".bashrc file to run," which indicates that the order of the terminal to load the file is first loaded into the .bash_profile file, and in .bash_profile .bashrc file and the source file, thus making loading the file .bash_profile .bashrc also load the file, so even if your environment is configured in the .bashrc is also run correctly. Enter the env can view information about the current configuration of your environment variables.

 

Summary : The problem is a lot of investigation and blog posts, but also a lot of monotony, when I searched for "Why every time you open the terminal under mac must be re-source .bash_profile", the search is all you say reads when the zsh, start a terminal installation .zshrc configuration files, this might say is right, but does not meet my situation is not what I want, then the situation should analyze carefully, for a kinds of ideas to answer this question, we must open the terminal every time you want to manually look .bash_profile source file, indicating that the terminal does not read the file start, then I had to search a bit, environment variable configuration file is loaded when the terminal starts at mac order, coupled with the emergence of this issue is not the original, indicating that turned out to be useful, and explain the configuration environment variable to the .bash_profile file is no problem, this problem is reduced to, why not read .bash_profile terminal starts file. These are the questions I was discovered and problem-solving ideas, there may be some long-winded, but I just want my entire problem-solving process and share ideas to other people, but also to sum up, easy to own, easy to others.

 

 

 

 

 

 

 

 

 

 

 

 

 

  

Guess you like

Origin www.cnblogs.com/yanht/p/11577809.html